Product Documentation

c-treeDB API for C++ - Developers Guide

Previous Topic

Next Topic

Adding an index to a table

If you need to add one or more indexes to an existing table, perform the following steps:

  1. Add the index by calling CTTable::AddIndex(). Repeat this step for each new index.
  2. Add, insert, or delete index segments by calling the overloaded methods CTTable::AddSegment(), CTTable::InsertSegment(), or CTTable::DelSegment(). Repeat this step for each segment of the index.
  3. Call CTTable::Alter() to add the new index

// add new index to table

CTTable ATable(ADatabase);


// open the table

ATable.Open("MyTable", CTOPEN_ NORMAL);


// add the new index

ATable.AddIndex("MyNewIndex", CTINDEX_FIXED, YES, NO);


// add new index segments

ATable.AddSegment("MyNewIndex", "Field1", CTSEG_SCHSEG);


// alter the table to commit index changes to disk

try

{

ATable.Alter(CTDB_ALTER_NORMAL);

}

catch (CTExplorer &err)

{

printf("Alter table failed with error %d\n", err.GetErrorCode());

}

TOCIndex