what is the difference between Delete and Truncate

Answer Posted / soorai ganesh

DELETE is a logged operation on a per row basis. This means that the deletion of each row gets logged and physically deleted.

You can DELETE any row that will not violate a constraint, while leaving the foreign key or any other contraint in place.

TRUNCATE is also a logged operation, but in a different way. TRUNCATE logs the deallocation of the data pages in which the data exists. The deallocation of data pages means that your data rows still actually exist in the data pages, but the extents have been marked as empty for reuse. This is what makes TRUNCATE a faster operation to perform over DELETE.

You cannot TRUNCATE a table that has any foreign key constraints. You will have to remove the contraints, TRUNCATE the table, and reapply the contraints.

TRUNCATE will reset any identity columns to the default seed value. This means if you have a table with an identity column and you have 264 rows with a seed value of 1, your last record will have the value 264 (assuming you started with value 1) in its identity columns. After TRUNCATEing your table, when you insert a new record into the empty table, the identity column will have a value of 1. DELETE will not do this. In the same scenario, if you DELETEd your rows, when inserting a new row into the empty table, the identity column will have a value of 265.

I believe its enough to you...............

Is This Answer Correct ?    4 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the importance of concurrency control?

661


Can sql servers linked to other servers like oracle?

540


How does clustered and non clustered index work?

512


When does the auto update index statistics feature in sql server turn itself on?q) what specific conditions database should meet, before you can bulk copy data into it using bcp?

572


Explain the working of sql privileges?

604






What does normalization do to data?

538


What is table value parameters (tvp)?

537


Explain what are the database objects? : SQL Server Architecture

559


Does union all remove duplicates?

605


Do you know what guidelines should be followed to help minimize deadlocks?

532


What is recompile sql server?

561


What is normalization? What number of normalization shapes are there?

600


What are sql azure firewall rules?

85


What is meant by referential integrity?

585


What is log shipping? Can we do logshipping with SQL Server 7.0 ?

570