Wednesday, July 8, 2009

Tip 43 – Removing Tables from a Dictionary

There are several ways to remove a table from a data dictionary. Tables can be removed using the DROP TABLE SQL statement and using the AdsDDRemoveTable API.

The DROP TABLE statement removes the table from the dictionary and deletes all of the table files, including memos and indexes. You can use the FROM DATABASE combined with the NO_DELETE option to remove the table from the data dictionary without deleting the files. This is the default behavior in ARC.

   1: // Remove the table from the dictionary and delete the files
   2: DROP TABLE Person
   3:  
   4: // Remove the table from the dictionary but keep the files
   5: DROP TABLE Person FROM DATABASE NO_DELETE

The AdsDDRemoveTable API works in much the same way. There are three parameters; Connection Handle, Table Name and a delete files flag.

   1: // Connect to the dictionary
   2: ADSHANDLE hConn;
   3: AdsConnect60( "C:\\Data\SampleDB\\SampleDB.ADD", ADS_REMOTE_SERVER, "ADSSYS",
   4:               NULL, ADS_DEFAULT, &hConn );
   5:  
   6: // Remove the department table and its files
   7: AdsDDRemoveTable( hConn, "Department", TRUE )
   8:  
   9: // Disconnect
  10: AdsDisconnect( hConn );

You must connect to the data dictionary with a user who has the right to drop tables in the dictionary in order to use either of these functions.

No comments: