Difference between Delete and Truncate

Difference Between Delete and Truncate

  .Delete table is a logged operation, so the deletion of each row gets logged in the transaction log, which makes it slow.
. Truncate table also deletes all the rows in a table, but it won't log the deletion of each row, instead it logs the de-allocation of the data pages of the table, which makes it faster. Of course, truncate table cannot be rolled back.
. Truncate table is functionally identical to delete statement with no "where clause" both remove all rows in the table. But truncate table is faster and uses fewer system and transaction log resources than delete.
. Truncate table removes all rows from a table, but the table structure and its columns, constraints, indexes etc., remains as it is.
. In truncate table the counter used by an identity column for new rows is reset to the seed for the column.
. If you want to retain the identity counter, use delete statement instead.
. If you want to remove table definition and its data, use the drop table statement.
. You cannot use truncate table on a table referenced by a foreign key constraint; instead, use delete statement without a where clause. Because truncate table is not logged, it cannot activate a trigger.
. Truncate table may not be used on tables participating in an indexed view.


TRUNCATE

.TRUNCATE removes all rows from a table, but the table structure, its columns, constraints, indexes and so on, remains. The counter used by an identity for new rows is reset to the seed for the column.
.You cannot use TRUNCATE TABLE on a table referenced by a FOREIGN KEY constraint. Because TRUNCATE TABLE is not logged, it cannot activate a trigger.
.TRUNCATE cannot be rolled back.
.TRUNCATE is DDL Command.
.TRUNCATE Resets identity of the table

DELETE
.DELETE removes rows one at a time and records an entry in the transaction log for each deleted row.

.DELETE Can be used with or without a WHERE clause
.DELETE Activates Triggers.
.DELETE can be rolled back.
.DELETE is DML Command.
.DELETE does not reset identity of the table

Truncate 

Resets identity of the table
DDL Command
Cannot be rolled back
Faster (Uses Fewer systems)
Where can't be used
removes the data by de-allocating the data pages
TRUNCATE removes all rows from a table, but the table structure, its columns, constraints, indexes and so on, remains. The counter used by an identity for new rows is reset to the seed for the column.
Trigger can't be activated


Delete
does not reset identity of the table
DML Command
can be rolled back
Slower (Removes row one by one)
WHERE Condition can be used
records an entry in the transaction log for each deleted row
Retain Identity counter
Trigger can be activated