TRUNCATE TABLE:

This SQL command removes all rows from a table without logging the individual row deletes. This allows TRUNCATE TABLE to be efficient and quick, but unrecoverable. The syntax for the command is

TRUNCATE TABLE [[database.]owner.]table_name

where

database: name of the database

owner: owner of the table and NOT the database

table_name: Specifies the table to be removed.

Remarks

TRUNCATE TABLE removes all rows from a table, but the table structure and all indexes. The TRUNCATE TABLE works similarly to the DELETE statement but is faster than DELETE. The DELETE statement removes rows one at a time and logs each deleted row as a transaction. TRUNCATE TABLE deallocates whole pages of data and makes fewer log entries. TRUNCATE TABLE guarantees that all rows are removed from the table and cannot be rolled back. DELETE can be rolled back. Both the DELETE and TRUNCATE TABLE statements reclaim the space occupied by the data and its associated indexes.

Back to the homepage