Friday, January 6, 2012

Truncate vs Delete

TRUNCATE:-
1) TRUNCATE is faster and uses fewer system and transaction log resources than DELETE.
2) TRUNCATE removes the date by deallocating the data pages used to store the table's data, and only the  page deallocations are recorded in the transaction log.
 3) TRUNCATE removes all the rows from a table, but the table structure, its columns, constraints, indexes, and permissions remain. You cannot use TRUNCATE TABLE on table referenced by a FOREIGN KEY constraint. As TRUNCATE cannot be rolled back unless it is used in a TRANSACTION
4)TRUNCATE is a DDL Command.
5)TRUNCATE resets the identity field of the table.

DELETE:
1) DELETE removes one record at a time, if used with a predicate in a where clause and records an entry in the transaction log for each deleted row.
2)If you want to retain the identity counter, use DELETE instead. If you want to remove table definition and its data, use the DROP TABLE statement.
3)DELETE can be used with or without a WHERE clause.
4)DELETE activate triggers.
5)DELETE can be rolled back.
6)DELETE is a DML Command.
7)DELETE does not reset the identity of the table.