Icon Emptying Tables

Introduction
Emptying tables is accomplished through the EmptyTable method of the TDBISAMTable component. The properties used by the EmptyTable method include the DatabaseName, TableName, and Exists properties. Emptying a table very quickly removes all of its records while keeping the structure, including indexes, intact.

Emptying a Table
To empty a table, you must specify the DatabaseName and TableName properties of the TDBISAMTable component and then call the EmptyTable method. The table can be open or closed when this method is called, however if the table is already open it must have been opened exclusively, meaning that the Exclusive property should be set to True. If the Exclusive property is set to False, an EDBISAMEngineError exception will be raised when this method is called. The error code given when emptying a table fails due to the table not being opened exclusively is 10253 and is defined as DBISAM_NEEDEXCLACCESS in the dbisamcn unit (Delphi) or dbisamcn header file (C++). If the table is closed when this method is called, then DBISAM will attempt to open the table exclusively before emptying the table. If another session has the table open then an EDBISAMEngineError exception will be raised when this method is called. The error code given when emptying a table fails due to the table being open by another session is 11013 and is defined as DBISAM_OSEACCES in the dbisamcn unit (Delphi) or dbisamcn header file (C++). It is usually good practice to also examine the Exists property of the TDBISAMTable component first to make sure that you don't attempt to empty a non-existent table. If you do attempt to empty a non-existent table an EDBISAMEngineError exception will be raised. The error code given when emptying a table fails due to the table not existing is 11010 and is defined as DBISAM_OSENOENT in the dbisamcn unit (Delphi) or dbisamcn header file (C++).

The following example shows how to empty the "customer" table using the EmptyTable method:

begin
   with MyDBISAMTable do
      begin
      DatabaseName:='d:\temp';
      TableName:='customer';
      if Exists then
         EmptyTable;
      end;
end;

Information You should be extremely careful when using this method since emptying a table will remove the contents of the table permanently. Be sure to have a backup of your data before using this method in order to avoid any costly mistakes.

In addition to using the TDBISAMTable EmptyTable method for emptying tables, DBISAM also allows the use of the EMPTY TABLE SQL statement.
Image