Following
are the differences between DELETE and TRUNCATE:
TRUNCATE
|
DELETE
|
TRUNCATE is DDL
Statement
|
DELETE is a DML
command
|
TRUNCATE cannot have
WHERE Conditions
|
DELETE can have
WHERE conditions
|
TRUNCATE does not
fire trigger
|
DELETE Fires TRIGGER
|
TRUNCATE reset the
identity to 0 (if table have any)
|
DELETE does not
RESET Identity
|
TRUNCATE Release the
table’s spaces to System
|
DELETE removes the
records but will not release the space to the system
|
TRUNCATE cannot be
used against the table that is referenced by a FOREIGN KEY constraint.
|
DELETE can be used
in tables reference by a Foreign Key and tables involved in Indexed view
|
TRUNCATE cannot be
used against the table used in Indexed view
|
DELETE can be used against
the table used in Indexed view
|
TRUNCATE apply Fewer
table locks
|
DELETE apply more
locks to the table
|
TRUNCATE cannot be
used against the tables involved in TRUNCATE transactional replication or
merge replication.
|
DELETE can be used
against table used transactional replication or merge replication
|
Less Transaction Log
entry because TRUNCATE TABLE removes the data by de-allocating the data pages
used to store the table data and records only the page de-allocations in the
transaction log and hence TRUNCATE is fast
|
DELETE FROM TABLE
command logs each record in transaction log, hence DELETE is slow.
|
Note:
TRUNCATE can be roll backed. Many programmers think that TRUNCATE can’t be roll
backed.
Comments
Post a Comment