Wednesday 10 June 2015

Difference between DELETE and TRUNCATE in SQL

DELETE
TRUANCATE
DELETE is DML Command.TRUNCATE is DDL Command.
DELETE Command is slowTRUNCATE is Faster
The DELETE command is used to remove specified rows from a table.TRUNCATE removes all rows from a table.
DELETE Can be used with or without a WHERE clauseNo WHERE clause is used
DELETE operation you need to COMMIT or ROLLBACKThe operation cannot be rolled back
DELETE does not reset identity of the table.TRUNCATE Resets identity of the table.
Trigger get firedTrigger doesn’t get fired
Syntax
DELETE
DELETE FROM table_name WHERE [condition]
e.g
DELETE FROM employee WHERE empid=100
TRUNCATE
TRUNCATE TABLE table_name
e.g
TRUNCATE TABLE employee

No comments:

Post a Comment