The DELETE
and TRUNCATE
commands in SQL are both used to remove data from a table but differ in several ways:
- DELETE:
- Removes rows one by one.
- Can include a
WHERE
clause to delete specific rows. - Slower, as it logs each row deletion.
- Can be rolled back (if used within a transaction).
- TRUNCATE:
- Removes all rows from the table.
- Cannot be used with a
WHERE
clause. - Faster, as it does not log individual row deletions.
- Cannot be rolled back in many database systems (unless within a transaction).
In summary, DELETE
offers more control, while TRUNCATE
is faster but less flexible.
Leave a comment