Product Documentation

FairCom DB API for C

Previous Topic

Next Topic

Creating the table

After all fields and indexes have been defined and the table properties set, it is time to create the table by calling ctdbCreateTable(). ctdbCreateTable() takes the table handle used to define fields and indexes, and to set the table properties, the table name and the create mode.

/* allocate a new table handle */

CTHANDLE hTable = ctdbAllocTable(hDatabase);


/* add two fields to the table record definition */

ctdbAddField(hTable, "Field0", CT_INTEGER, 4);

ctdbAddField(hTable, "Field1", CT_CHAR, 30);


/* add index 0 - the first index */

ctdbAddIndex(hTable, "MyIndex1", CTINDEX_FIXED, YES, NO);


/* add index 0 segments */

ctdbAddSegmentByName(hTable, 0, "Field0", CTSEG_SCHSEG);


/* add index 1 - the second index */

ctdbAddIndex(hTable, "MyIndex2", CTINDEX_FIXED, NO, NO);


/* add index 1 segments */

ctdbAddSegmentByName(hTable, 1, "Field1", CTSEG_SCHSEG);

ctdbAddSegmentByName(hTable, 1, "Field0", CTSEG_SCHSEG);


/* create the table */

ctdbCreateTable(hTable, "MyTable", CTCREATE_NORMAL);

The table create modes are a combination of the following valid modes. You can specify more than one create mode by OR-ing the following constants together.

For a list of modes for creating a table, see Table Create Modes.

Note that if you wish to use transaction processing (the ctdbBegin(), ctdbCommit(), and ctdbAbort() functions) to ensure atomicity, then it is important to create the table using the CTCREATE_PREIMG or the CTCREATE_TRNLOG mode. If you think your table might get big (larger than 2 gigabytes), be sure to OR in CTCREATE_HUGEFILE.

TOCIndex