Solved

SQL Table Index and Key Information

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now