DELETE
- DELETE is a DML Command.
- DELETE statement is executed using a row lock, each row in the table is locked for deletion.
- We can specify filters in where clause
- It deletes specified data if where condition exists.
- Delete activates a trigger because the operation are logged individually.
- Slower than truncate because, it keeps logs.
- Rollback is possible.
TRUNCATE
- TRUNCATE is a DDL command.
- TRUNCATE TABLE always locks the table and page but not each row.
- Cannot use Where Condition.
- It Removes all the data.
- TRUNCATE TABLE cannot activate a trigger because the operation does not log individual row deletions.
- Faster in performance wise, because it doesn’t keep any logs.
- Rollback is possible.
- DELETE and TRUNCATE both can be rolled back when used with
TRANSACTION (TRUNCATE can be rolled back in SQL Server, but not in MySQL). - if there is a PK with auto increment, truncate will
reset the counter
http://beginner-sql-tutorial.com/sql-delete-statement.htm