You are on page 1of 2

TRUNCATE DELETE

TRUNCATE is a DDL command DELETE is a DML command


TRUNCATE is executed using a table DELETE is executed using a row lock,
lock and whole table is locked for each row in the table is locked for
remove all records. deletion.
We cannot use Where clause with We can use where clause with DELETE
TRUNCATE. to filter & delete specific records.
TRUNCATE removes all rows from a The DELETE command is used to
table. remove rows from a table based on
WHERE condition.
Minimal logging in transaction log, so it It maintain the log, so it slower than
is performance wise faster. TRUNCATE.
TRUNCATE TABLE removes the data by The DELETE statement removes rows
deallocating the data pages used to one at a time and records an entry in
store the table data and records only the transaction log for each deleted row
the page deallocations in the
transaction log.
Identify column is reset to its seed Identity of column keep DELETE retain
value if table contains any identity the identity
column.
To use Truncate on a table you need at To use Delete you need DELETE
least ALTER permission on the table. permission on the table.
Truncate uses the less transaction space Delete uses the more transaction space
than Delete statement. than Truncate statement.
Truncate cannot be used with indexed Delete can be used with indexed views
views
Drop all object’s statistics and marks Keeps object’s statistics and all
like High Water Mark free extents and allocated space. After a DELETE
leave the object really empty with the statement is executed, the table can
first extent. zero pages are left in the still contain empty pages.
table
TRUNCATE TABLE can’t activate a Delete activates a trigger because the
trigger because the operation does not operation are logged individually. When
log individual row deletions. When we we execute Delete command, DELETE
run truncate command to remove all trigger will be initiated if present. Delete
rows of table then it actually doesn’t is a DML command and it deletes the
removes any row, rather it deallocates data on row-by-row basis from a table.
the data pages. In case of Truncate Which means delete is modifying the
triggers will not be fired because no data by deleting it from the table.
modification takes place, we have just Triggers are fired when a DML
deallocated the data pages not deleted statement executed on a table, so
any row from table. trigger will be fired in case of Delete
command execution.

- See more at: http://www.softwaretestingclass.com/difference-between-truncate-and-


delete-statement-in-sql-server/#sthash.wJHG1yni.dpuf

Truncate is DDL meaning all the data will be lost and only structure remains and we cant rollback
Delete is DML meaning..we delete the required data or all the data and then we have an option of rolling
back the changes...

truncate --- ddl statement


so no rollback segment needed
so much faster than delete
data cannot be retrieved in normal conditions
since ddl so no explicit commit is required

delete --- dml


rollback segment required
a bit slower
selective data can be deleted using where condition
commit needs to be done to complete the transaction

You might also like