Tuesday, March 20, 2012

Truncate vs Delete

TRUNCATE VS DELETE


Truncate
Delete
Where clause
Can’t apply.
Yes.
Identity property
Resets the Identity property
identity property values will remain same
Triggers
Wont fire
Triggers will fire
Performance
Minimally logged transaction.
There is a myth that Truncate is a non-logged operation and can’t include in “begin tran” that is not true. it only logs the page de-allocations . there is no such thing called "non-logged" operation in SQL Server.
fully logged transaction
References
Can’t execute truncate table when the table has references.
Can execute the delete statement on a table with references with an exception that there won’t be any corresponding records in referencing table.
On indexed views
Cant execute when the table has indexed view
Supports
Locks
Less no.of locks
More locks
T-Log Space
Less transaction log space
Size and no of logged transactions are more.
Replication
Can’t use when the table participating in transactional or merge replication
 Supports

No comments:

Post a Comment

Featured Post

SQL Server AWS Migration BCP

stored procedure to generate BCP scritps to migrate the SQL Server database. Developed this stored procedure on my labs to simulate t...

Contributors