Solved

SQL Table Index and Key Information

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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Wininet read php file from internet issue 6 91
When i run adoquery my application freezes 26 166
Dev express lookupcombo 3 28
Multi-layered image in FireMonkey 9 34
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

777 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