Adding or deleting indicesIndices and index segments are key-based search tools that make record seeking faster and more efficient. An index is a mapping table that contains keys describing certain records and pointers to those records. An index segment describes the table field from which the keys are created. Indices are added to the table definition in the order they are declared. The c-treeDB API also includes a set of functions that will allow an index to be deleted from the table index definition. CTTable::AddIndex() will add a new index at the end of the table index definition. For each index added to the table, one or more index segments should also be added to define which field combination form a particular index. CTTable::AddSegment() overloaded methods will accomplish the task of adding segments to an index. // create a new table object CTTable ATable(ADatabase);
ATable.AddField(“Field1”, CT_INTEGER, 4); ATable.AddField(“Field2”, CT_CHAR, 30);
ATable.AddIndex(“MyIndex1”, CTINDEX_FIXED, YES, NO);
ATable.AddSegment(“MyIndex1”, “Field1”, CTSEG_SCHSEG);
ATable.AddIndex(“MyIndex2”, CTINDEX_FIXED, NO, NO);
ATable.AddSegment(“MyIndex2”, “Field2”, CTSEG_SCHSEG); ATable.AddSegment(“MyIndex2”, “Field1”, CTSEG_SCHSEG);
try {
ATable.Create(“MyTable”, CTCREATE_NORMAL); } catch (CTException &err) {
printf(“Create table failed with error %d\n”, err.GetErrorCode()); } The CTTable::AddIndex() method takes an index name, index type, and two Boolean flags indicating if the index accepts duplicate keys and if the index should process null keys. The valid index types are:
Note: c-treeDB.NET Index Key Types are defined in the KEY_TYPE enum.The add and insert segment functions require a segment mode to be passed as the last parameter. Please refer to "Segment Modes" describing the valid segment modes. An index can be deleted from the table index definition by calling one of CTTable::DelIndex() overloaded methods. // create a new table object CTTable ATable(ADatabase);
ATable.AddField(“Field1”, CT_INTEGER, 4); ATable.AddField(“Field2”, CT_CHAR, 30);
ATable.AddIndex(“MyIndex1”, CTINDEX_FIXED, YES, NO);
ATable.AddSegment(“MyIndex1”, “Field1”, CTSEG_SCHSEG);
ATable.AddIndex(“MyIndex2”, CTINDEX_FIXED, NO, NO);
ATable.AddSegment(“MyIndex2”, “Field2”, CTSEG_SCHSEG); ATable.AddSegment(“MyIndex2”, “Field1”, CTSEG_SCHSEG);
ATable.DelIndex(“MyIndex1”);
try {
ATable.Create(“MyTable”, CTCREATE_NORMAL); } catch (CTException &err) {
printf(“Create table failed with error %d\n”, err.GetErrorCode()); } |
|||||||||||||||||||||