![]() | ![]() Products ![]() ![]() ![]() ![]() |
Home » Technical Support » DBISAM Technical Support » Product Manuals » DBISAM Version 4 Manual for RAD Studio XE (C++) » 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. ![]() |
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. |
{ MyTable->DatabaseName="d:\\temp"; MyTable->TableName="customer"; MyTable->FieldDefs->Clear(); MyTable->FieldDefs->Add("CustNo",ftFloat,0,true); MyTable->FieldDefs->Add("Company",ftString,30,false); MyTable->FieldDefs->Add("Addr1",ftString,30,false); MyTable->FieldDefs->Add("Addr2",ftString,30,false); MyTable->FieldDefs->Add("City",ftString,15,false); MyTable->FieldDefs->Add("State",ftString,20,false); MyTable->FieldDefs->Add("Zip",ftString,10,false); MyTable->FieldDefs->Add("Country",ftString,20,false); MyTable->FieldDefs->Add("Phone",ftString,15,false); MyTable->FieldDefs->Add("FAX",ftString,15,false); MyTable->FieldDefs->Add("Contact",ftString,20,false); MyTable->IndexDefs->Clear(); MyTable->IndexDefs->Add("","CustNo",TIndexOptions() << ixPrimary); MyTable->IndexDefs->Add("ByCompany","Company", TIndexOptions() << ixCaseInsensitive, "",icDuplicateByte); if (!MyTable->Exists()) { MyTable->CreateTable(); } }
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
{ MyTable->DatabaseName="c:\\temp"; MyTable->TableName="customer"; // Always make sure the table is closed first MyTable->Active=False; // Update the field definitions using the // existing field definitions from the table MyTable->FieldDefs.Update(); // Same for the index definitions MyTable->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 MyTable->FieldDefs.Insert(6,8,"LastSaleAmount",ftBCD,2,false); MyTable->IndexDefs.Add("LastSaleAmount","LastSaleAmount", TIndexOptions()); // Now alter the table's structure AlterTable(); }
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 Policy![]() © 2024 Elevate Software, Inc. All Rights Reserved Questions or comments ? ![]() |