Tutorials and code for ASP.NET 2.0,C#,SQL Server,AJAX tutorials,jQuery  
Home    Articles    Contact Us
 

ASP.NET
AJAX
Interview Questions
Sql Server
Technology News
Tips and Tricks
jQuery

 

Difference between Truncate and Delete in SQL


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.

  • TRUNCATE is a DDL (data definition language) command whereas DELETE is a DML (data manipulation language) command.

  • You can use WHERE clause(conditions) with DELETE but you can't use WHERE clause with TRUNCATE .

  • You cann't rollback data in TRUNCATE but in DELETE you can rollback data.TRUNCATE removes(delete) the record permanently.

  • A trigger doesn’t get fired in case of TRUNCATE whereas Triggers get fired in DELETE command.

  • If tables which are referenced by one or more FOREIGN KEY constraints then TRUNCATE will not work.

  • TRUNCATE resets the Identity counter if there is any identity column present in the table where delete not resets the identity counter.

  • 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.

  • TRUNCATE is faster than DELETE.

 

Related Articles:



User Comments:

Comment By Bart Czernicki on 01/03/2009

The rollback comment is not 100% true. You can rollback truncate statements under certain conditions. http://sql-server-performance.com/Community/forums/p/16968/99791.aspx
Comment By amrelgarhy on 01/03/2009

Nice to know that, very helpful
Comment By WebDevVote.com on 01/05/2009

Track back from http://webdevvote.com/AspNet/Difference_between_Truncate_and_Delete_in_SQL
Comment By asasas on 11/02/2009

asasasasasasasasasasasasa
Comment By asasasasasas on 11/02/2009

asasasas
Comment By Ramakrishnan on 11/18/2009

Excellent information. Thanks
Comment By amit on 06/24/2010

gr8 difference showing here
Comment By Raj Kumar Sharma on 07/28/2010

how can say that truncate is faster than the delete process
Comment By Raj Kumar Sharma on 07/28/2010

how can say that truncate is faster than the delete process
Comment By Raj Kumar Sharma on 07/28/2010

how can say that truncate is faster than the delete process


Post Your Comment :


Name
Email:
Comment:

Home | Contact Us

© 2008-09 TechnoReader.com. All rights reserved.