Login ProductsSalesSupportDownloadsAbout |
Home » Technical Support » DBISAM Technical Support » Product Manuals » DBISAM Version 4 Manual for RAD Studio XE (Delphi) » Using DBISAM » Creating and Altering Tables |
Value | Rules |
Field Number | A field number is 1-based, meaning that it starts at 1 for the first field definition in a table. A field number is automatically assigned for all field definitions when creating a table so it need not be specified and will be ignored if specified. When altering the structure of an existing table, a field number is required for each field definition. As indicated above, using the FieldDefs property's Update method will automatically populate the correct field numbers from an existing table. If adding a new field, the field number should be set to the next largest field number based upon the existing field numbers in the FieldDefs property. For example, if you have 5 field definitions in the FieldDefs property and wish to add another, the new field definition should be specified with 6 as its field number. The field definitions represented by the FieldDefs property can have gaps in the field numbers when altering the structure of an existing table. The is because it is possible that a given field definition has been deleted, which means that its field number would not be present anywhere in the field definitions. This type of condition is exactly what indicates to DBISAM that the field should be removed from the table structure.
|
Index Position | An index position is 0-based, meaning that the first field definition is at index position 0, the second field definition at index position 1, etc. When creating a table or altering the structure of an existing table, the index position represents the desired physical position of the field definition in the table after the table creation or alteration takes place. When altering the structure of an existing table, you can move field definitions around to different index positions and leave their field numbers intact. This will indicate to DBISAM that the field has simply moved its position in the structure of the table. You can also use the Insert method to insert a field definition at a specific index position. Like the Add method, there are two versions of the Insert method, one with a FieldNo parameter for use when altering the structure of an existing table and one without for use when creating a table. |
begin with MyTable do begin DatabaseName:='d:\temp'; TableName:='customer'; with FieldDefs do begin Clear; Add('CustNo',ftFloat,0,True); Add('Company',ftString,30,False); Add('Addr1',ftString,30,False); Add('Addr2',ftString,30,False); Add('City',ftString,15,False); Add('State',ftString,20,False); Add('Zip',ftString,10,False); Add('Country',ftString,20,False); Add('Phone',ftString,15,False); Add('FAX',ftString,15,False); Add('Contact',ftString,20,False); end; with IndexDefs do begin Clear; Add('','CustNo',[ixPrimary]); Add('ByCompany','Company',[ixCaseInsensitive], '',icDuplicateByte); end; if not Exists then CreateTable; end; end;
Customer Table Structure Before Alteration Field # Name DataType Size ---------------------------------------------- 1 CustomerID ftString 10 2 CustomerName ftString 30 3 ContactName ftString 30 4 Phone ftString 10 5 Fax ftString 10 6 EMail ftString 30 7 LastSaleDate ftDate 0 Index Name Fields In Index Options ---------------------------------------------- (none) CustomerID ixPrimary
begin with MyTable do begin DatabaseName:='c:\temp'; TableName:='customer'; { Always make sure the table is closed first } Active:=False; { Update the field definitions using the existing field definitions from the table } FieldDefs.Update; { Same for the index definitions } IndexDefs.Update; { Now insert the new field definition. Notice the index position of 6 which is 0-based and the field number of 8 which is 1-based and equal to the next available field number since there are currently 7 field definitions for this table } FieldDefs.Insert(6,8,'LastSaleAmount',ftBCD,2,False); IndexDefs.Add('LastSaleAmount','LastSaleAmount',[]); { Now alter the table's structure } AlterTable; end; end;
Customer Table Structure After Alteration Field # Name DataType Size ---------------------------------------------- 1 CustomerID ftString 10 2 CustomerName ftString 30 3 ContactName ftString 30 4 Phone ftString 10 5 Fax ftString 10 6 EMail ftString 30 7 LastSaleAmount ftBCD 2 8 LastSaleDate ftDate 0 Index Name Fields In Index Options ---------------------------------------------- (none) CustomerID ixPrimary LastSaleDate LastSaleDate (none)
Original Extension | Backup Extension |
.dat (data) | .dbk |
.idx (indexes) | .ibk |
.blb (BLOBs) | .bbk |
This web page was last updated on Thursday, November 16, 2023 at 10:39 AM | Privacy PolicySite Map © 2024 Elevate Software, Inc. All Rights Reserved Questions or comments ? E-mail us at info@elevatesoft.com |