Difference between DELETE and TRUNCATE COmmand
Delete command removes the rows from a table based on the condition thate 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 can run the truncate command.
Truncate: Truncate is faster and uses fewer system and transaction log resources than Delete. Truncate removes the data by deallocationg the data pages used to store the tables's data,and only the page deallocations are recorded in the transaction log. Truncate removes all rows froma table ,but the table structure and its columns ,constraints ,indexes and so on remain.The counter used by an idetity for new rows is reset to the seed for the column. You cannot use Truncate table on a tbale referenced by a Foreign key constant.Because Truncate table is not logged,it cannot activate a trigger. Truncate cannot be rolled back. Truncate is dll 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 u want to remove table definition and its data,use the DROP TABLE statement. Delete can be used with or without a WHERE clause. Delete activate triggers. Delete can be rolled back. Delete is DML command. Delete does not reset identity of the table
|
| Author: Roopesh Babu Valluru 14 Oct 2008 | Member Level: Gold Points : 1 |
good article man...
i knew many but it helped to know all ... :)
Thx a lot....
|