what is the difference between Delete and Truncate

Answers were Sorted based on User's Feedback



what is the difference between Delete and Truncate..

Answer / 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

what is the difference between Delete and Truncate..

Answer / bhaskar

What is difference between DELETE & TRUNCATE commands?
Delete command removes the rows from a table based on the
condition that we provide with a WHERE clause. Truncate
will actually remove all the rows from a table and there
will be no data in the table after we run the truncate
command.
TRUNCATE
TRUNCATE is faster and uses fewer system and transaction
log resources than DELETE.
TRUNCATE removes the data by deallocating the data pages
used to store the table’s data, and only the page
deallocations are recorded in the transaction log.
TRUNCATE removes all rows from a table, but the table
structure and its columns, constraints, indexes and so on
remain. The counter used by an identity for new rows is
reset to the seed for the column.
You cannot use TRUNCATE TABLE on a table referenced by a
FOREIGN KEY constraint.
Because TRUNCATE TABLE is not logged, it cannot activate a
trigger.
TRUNCATE can not be Rolled back using logs.
TRUNCATE is DDL Command.
TRUNCATE Resets identity of the table.



DELETE
DELETE removes rows one at a time and records an entry in
the transaction log for each deleted row.
If you want to retain the identity counter, use DELETE
instead. If you want to remove table definition and its
data, use the DROP TABLE statement.
DELETE Can be used with or without a WHERE clause
DELETE Activates Triggers.
DELETE Can be Rolled back using logs.
DELETE is DML Command.
DELETE does not reset identity of the table.

Is This Answer Correct ?    1 Yes 0 No

what is the difference between Delete and Truncate..

Answer / anil sharma

Delete command execute row by row and it can't reset any
identity column's value.
But using Truncate command it reset all table and Identity
column also.So truncate command is fast then delete command.

Is This Answer Correct ?    0 Yes 0 No

what is the difference between Delete and Truncate..

Answer / manoj pandey

Check following blog post for Difference Delete vs Truncate: http://sqlwithmanoj.wordpress.com/2009/02/22/difference-between-truncate-delete-and-drop-commands/

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More SQL Server Interview Questions

How to create a new schema in a database?

0 Answers  


Can you explain the disadvantages/limitation of the cursor?

0 Answers  


Determine when an index is appropriate?

0 Answers  


What are the acid properties?

0 Answers  


What is update locks?

0 Answers  






Why would you call update statistics?

0 Answers  


What is @@error in sql?

0 Answers  


What is an extended stored procedure? Can you instantiate a COM object by using T-SQL?

3 Answers   HCL,


Name the different type of indexes in sql?

0 Answers  


Explain sp_configure commands, set commands?

3 Answers  


How to test subquery results with the exists operator?

0 Answers  


Can some one please help with a query which will take only max value of a column in a join.

2 Answers  


Categories