Previous Topic

Next Topic

Dropping a table under transaction control

An extra level of data integrity can be achieved when you drop a table from a database under transaction control. When the transaction is committed, the changes to the database dictionary data for the table are committed to disk. If the transaction is aborted, the dictionary data for the table is automatically restored to the database dictionary.

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

// start a transaction
ADatabase.Begin();
try
{
   // drop MyTable from current database
   ADatabase.DropTable(“MyTable”);
   // commit the transaction
   ADatabase.Commit();
}
catch (CTException &err)
{
   // abort the transaction
   ADatabase.Abort();
   printf(“Drop table failed with code %d\n”, err.GetErrorCode());
}