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 do I find information about the install locations for the various instances running on a computer?
Tell me what are the advantages of using stored procedures?
What is the use of tempdb? What values does it hold?
How do you clear a log file?
Is port 1433 secure?
In what version of sql server were synonyms released?
What will be the maximum number of indexes per table?
What is ems sql management studio? : sql server management studio
In which format does an image save in SQL Server database ?
Does windows server 2016 come with sql server?
List some of the rules that apply to creating and using a ‘view’
What are the different types of stored procedures?
What happens if you are trying to access a schema not owned by you?
What happens to a trigger with multiple affected rows?
What is self contained scalar sub query?