Previous Topic

Next Topic

Deleting a table under transaction control

An extra level of data integrity may be achieved when you delete a table from a database under transaction control. When the transaction is committed the changes to the database dictionary data for the table is committed to disk and the table and index files are deleted from disk. If the transaction is aborted, the dictionary data for the table is automatically restored to the database dictionary and the original data and index files are restored to their original state.

The code fragment below shows how to delete an existing table under transaction control. No error checking is included in the sample code:

/* start a transaction */
ctdbBegin(hDatabase);

/* delete MyTable from current database */
if (ctdbDeleteTable(hDatabase, “MyTable”, NULL) != CTDBRET_OK) {
   printf(“Delete table failed\n”);
   ctdbAbort(hDatabase);
} else {
   printf(“Delete table\n”);
   ctdbCommit(hDatabase);
}