Tuesday, 21 February 2012

Q: What is different truncate and delete?


Truncate an Delete both are used to delete data from the table. These both command will only delete data of the specified table, they cannot remove the whole table data structure.Both statements delete the data from the table not the structure of the table.
1.       You can use WHERE clause(conditions) with DELETE but you can't use WHERE clause with TRUNCATE .
2.       If tables which are referenced by one or more FOREIGN KEY constraints then TRUNCATE will not work.
3.       Delete and Truncate both are logged operation.But DELETE is a logged operation on a per row basis and TRUNCATE logs the deallocation of the data pages in which the data exists
4.       TRUNCATE is faster than DELETE.

No comments:

Post a Comment