Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 211
  • Last Modified:

SQL Table Index and Key Information

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
Llysander
Asked:
Llysander
1 Solution
 
rwilson032697Commented:
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
 
LlysanderAuthor Commented:
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
 
skanovkoCommented:
You mean using TBatchMove component from Delphi's VCL ?
0
 
LlysanderAuthor Commented:
Correct.
0
 
slautinCommented:
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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now