Wednesday, 29 July 2015

Difference between Delete & Truncate

DELETE
TRUNCATE
Delete is a DML Command.
Truncate is a DDL Command.
We can use Where Clause with Delete to delete Specific Records.
We Cannot use Where Clause with Truncate.
It Maintains the Logs, So It Slower than Truncate
It Won't maintain the Logs, So it is Performance Wise Faster
Identity Of Column Keep Delete Retain the Identity
Identity Column is Reset to its seed Value if the table Contains any Identity Column
To Use Delete we need Delete Permission on the Table
To Use Truncate on Table we need at least Alter Permission on the Table
Delete Can be used with Indexed Views
Truncate Cannot be used with Indexed Views
Delete Activates a Trigger because the Operation are logged Individually. When we Execute Delete Command, Delete Trigger will be initiated if present. Delete is a DML Command and it deletes the data Row-by-Row basis from a Table. Which means delete is modifying the data by deleting it from the table. Triggers are fired when a DML statement executed on a table, So Trigger will be fired in case of Delete Command Execution.
Truncate Table Can't activate a Trigger because the Operation does not log individual row deletions. When we run truncate command to remove all rows of table then it actually doesn't removes any row, rather it de-allocates the data pages. In case of Truncate triggers will not be fired because no modifications takes place, we have just de-allocated the data pages not deleted any row from table.

No comments:

Post a Comment