To remove all rows from a table, the TRUNCATE table statement is a quick and efficient method. TRUNCATE TABLE is similar to a DELETE statement that does not contain a WHERE clause. However, TRUNCATE TABLE is faster and uses fewer system resources and transaction log resources.
TRUNCATE TABLE has the following advantages over the DELETE statement:
Less transaction log space is used.
The DELETE statement deletes one row at a time and records an item in the transaction log for each row that is deleted. TRUNCATE table deletes data by releasing the data page used to store the table data, and only the page release is recorded in the transaction log.
The locks used are usually less.
When you execute a DELETE statement by using a row lock, the rows in the table are locked for deletion. TRUNCATE table always locks tables and pages instead of locking rows.
Without exception, no pages will be left in the table.
After the DELETE statement is executed, the table will still contain empty pages. For example, you must use at least one exclusive (lck_m_x) table lock to free up empty tables in the heap. If you do not use a table lock when you perform a delete operation, many empty pages will be included in the table (heap). For indexes, the delete leaves some empty pages, although these pages are released quickly through the background cleanup process.
As with the DELETE statement, the definition of a table emptied with TRUNCATE table is persisted with its index and other associated objects in the database. If the table contains an identity column, the counter of the column is reset to the seed value defined by the column. If no seed is defined, the default value of 1 is used. To preserve the identity counter, use DELETE.
Oracle uses TRUNCATE table to delete all rows