What is difference between TRUNCATE and DELETE statement

Answer Posted / shireen

TRUNCATE TABLE is functionally identical to DELETE
statement with no WHERE clause: both remove all rows in the
table. But TRUNCATE TABLE is faster and uses fewer system
and transaction log resources than DELETE.

The DELETE statement removes rows one at a time and records
an entry in the transaction log for each deleted row.
TRUNCATE TABLE 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 TABLE 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. 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.

You cannot use TRUNCATE TABLE on a table referenced by a
FOREIGN KEY constraint; instead, use DELETE statement
without a WHERE clause. Because TRUNCATE TABLE is not
logged, it cannot activate a trigger.

TRUNCATE TABLE may not be used on tables participating in
an indexed view.

Is This Answer Correct ?    3 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

what is the main function of a query parameter?

126


Can we take the full database backup in log shipping?

769


what is raid and what are different types of raid configurations? : Sql server database administration

781


What is checkpoint in sql server?

864


What is faster join or union?

845


what is the difference in login security modes between v6.5 and 7.0? : Sql server database administration

877


Differentiate between truncate vs delete in mssql?

737


Mention the 3 ways to get a count of the number of records in a table.

766


How to stop log file growing too big?

796


What are the five characteristics of good data?

719


What is openrowset sql server?

815


How to list all field names in the result set using mssql_field_name()?

720


Explain about analysis services?

805


How is sql used in sql server?

719


What is sql azure database?

198