Solution
The delete command removes the rows from a table on the basis of the condition that we provide a WHERE clause.
Truncate will actually remove all of 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 the rows from a table, but the table structure, its columns, constraints, indexes, and permissions remain. You cannot use TRUNCATE TABLE on a table referenced by a FOREIGN KEY constraint. As TRUNCATE TABLE is not logged, it cannot activate a trigger.
TRUNCATE cannot be rolled back unless it is used in a TRANSACTION.
TRUNCATE is a DDL Command.
TRUNCATE resets the identity field of the table
DELETE
DELETE removes one record at a time If used with a predicate in a where clause 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.
DELETE is a DML Command.
DELETE does not reset the identity of the table.
Thanks for reading this article,
Next steps :
- Share this with your colleagues because Sharing is Learning
- Comment below if you need any assistance