Can you tell me the difference between DELETE & TRUNCATE
commands?
Answer Posted / afzal_aziz
Truncate:
- deallocates the data pages in a table and only this
deallocation is stored in transaction log
- aquires only table and page locks for the whole table.
since no row locks are used less memory is required (lock
is a pure memory object)
- resets identity column if there is one
- removes ALL pages. NO empty pages are left behind in a
table
- fast(er)
- doesn't fire delete triggers
Delete:
- removes one row at the time and every deleted row is
stored in the transaction log
- aquires table and/or page and row locks for the whole
table
- leaves identity column alone
- can leave empty pages in a table since empty page
removal requires a table lock which doesn't necessarily
happen
- slow(er)
- fires delete triggers
http://weblogs.sqlteam.com/mladenp/archive/2007/10/03/SQL-
Server-Why-is-TRUNCATE-TABLE-a-DDL-and-not.aspx
| Is This Answer Correct ? | 8 Yes | 6 No |
Post New Answer View All Answers
How to download microsoft sql server 2005 express edition?
What is attribute hierarchy? : sql server analysis services, ssas
What is the difference between a function and a trigger?
Explain the difference between function and stored procedure?
What is the difference between varchar and varchar(max) datatypes?
What is apply operator in sql?
How do you rename a table in sql server?
Explain can you implement data mining in ssrs?
When would you use it?
Do you know what guidelines should be followed to help minimize deadlocks?
What are “unrepeatable reads”?
You want to use bids to deploy a report to a different server than the one you chose in the report wizard. How can you change the server url?
What is page-level compression?
What are the steps you can take to avoid “deadlocks”?
Define synonym?