Solved

SQL Table Index and Key Information

Posted on 1998-12-07
5
204 Views
Last Modified: 2010-04-04
When performing a BatchMove, how do I also transfer the Key and Index information.

Scenario: Two database servers, connect to a table on server one and batch copy it to server two.  How to I also copy all of the indexes and Primary/Foriegn key information?
0
Comment
Question by:Llysander
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1349753
The indexes will happen automatically if the tables on server two have had the indexes created for them. The key information itself is just values being copied so that will happen automatically.

Cheers,

Raymond.
0
 

Author Comment

by:Llysander
ID: 1349754
True, but if table 2 does yet exist and is being created by the BatchMove process ie. batCopy mode the destination will not contain any indexing.  How do I migrate the source indexes and key information?
0
 

Expert Comment

by:skanovko
ID: 1349755
You mean using TBatchMove component from Delphi's VCL ?
0
 

Author Comment

by:Llysander
ID: 1349756
Correct.
0
 
LVL 1

Accepted Solution

by:
slautin earned 50 total points
ID: 1349757
I think you must copy tables without indexes ant after all
make indexes.

At first:
Information On indexes is come alive to get by means of functions
DbiOpenIndexList.
Sample:
procedure fDbiOpenIndexList(Tbl: TTable; var IndexList: TStringList);
var
  TmpCursor: hdbicur;
  rslt: dbiResult;
  IndexDesc: IDXDesc;
begin
  Check(DbiOpenIndexList(Tbl.dbhandle, PChar(Tbl.TableName),
       nil, TmpCursor));
  IndexList.Clear;
  repeat
    rslt:= DbiGetNextRecord(TmpCursor, dbiNOLOCK, @IndexDesc,
       nil);
    if (rslt <> DBIERR_EOF) then
    begin
      IndexList.Add(StrPas(IndexDesc.szName))
    end;
  until rslt <> DBIERR_NONE;
  Check(DbiCloseCursor(TmpCursor));

end;

At second. DbiGetIndexDescs retrieves index properties for all indexes associated with this cursor.

Sample:

procedure ShowIndexDescs(T: TTable);
const
  IDXStr =
   '%sIndex name: %s.  Number of fields in key: %d'#13#10;
var
  CurProp: CURProps;
  pIndexDesc, pTmpMem: pIdxDesc;
  i, MemSize: integer;
  ShowString, IDXName: string;
begin
  Check(DbiGetCursorProps(T.Handle, CurProp));
  MemSize := CurProp.iIndexes * sizeof(IDXDesc);
  pIndexDesc := AllocMem(MemSize);
  try
    pTmpMem := pIndexDesc;
    Check(DbiGetIndexDescs(T.Handle, pIndexDesc));
    i := 0;
    ShowString := '';

    while (i < curProp.iIndexes) do begin
      with pTmpMem^ do begin
     // primary index does not have a name for PARADOX tables }
    if bPrimary and (StrComp(curProp.szTableType, szParadox) =
         0) then
          IDXName := 'Primary'
        else
          IDXName := szName;
     ShowString := Format(IDXStr, [ShowString, IDXName,
         iFldsInKey])
      end;
      // increment pointer to the next record
      inc(pTmpMem);
      inc(i);
    end;
  finally

    FreeMem(pIndexDesc, MemSize);
    ShowMessage(ShowString);
  end;
end;
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question