Solved

SQL Table Index and Key Information

Posted on 1998-12-07
5
203 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
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
delphi exception 7 68
indy Tmemory stream non latin charcter issue 2 121
Run video youtube webbrowse 10 65
Delphi problems to abort a printjob 9 25
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
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…

820 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