Enterprise Edition Home | Express Edition Home | Previous Page | Next Page   SQL Statements > TRUNCATE (IDS) > 4 4 4

Performance Advantages of TRUNCATE

4

The TRUNCATE statement is not equivalent to DROP TABLE. After TRUNCATE 4successfully executes, the specified table and all 4its columns and indexes are still registered in the database, but with no 4rows of data. In information management applications that require replacing 4all of the records in a table after some time interval, TRUNCATE requires 4fewer updates to the system catalog than the equivalent DROP TABLE, CREATE 4TABLE, and any additional DDL statements to redefine any synonyms, views, 4constraints, triggers, privileges, fragmentation schemes, and other attributes 4and associated database objects of the table.

4

In contexts where no existing rows of a table are needed, the TRUNCATE 4statement is typically far more efficient than using the DELETE statement 4with no WHERE clause to empty the table, because TRUNCATE requires fewer resources 4and less logging overhead than DELETE:

4 4

These performance advantages of TRUNCATE over DELETE are reduced when the 4table has one or more columns with the following attributes:

4

Each of these features require the database server to read each row of 4the table, substantially reducing the speed of TRUNCATE.

4

If a table includes one or more UDTs for which you have registered an am_truncate( ) purpose function, then the performance difference 4between TRUNCATE and DELETE would reflect the relative costs of invoking the am_truncate interface once for TRUNCATE versus invoking 4the destroy support function for each row.

4

As listed in the next section, certain conditions cause TRUNCATE to fail 4with an error. Some of these conditions have no effect on DELETE operations, 4so in those cases you can remove all rows more efficiently with a DELETE statement, 4as in the following operation on the customer table:

4

4
DELETE customer;

The FROM keyword that immediately follows DELETE 4can be omitted, as in this example, only if the DELIMIDENT environment variable is set.

Enterprise Edition Home | Express Edition Home | [ Top of Page | Previous Page | Next Page | Contents | Index ]