1 Answers
TRUNCATE vs DELETE in T-SQL
In T-SQL, TRUNCATE and DELETE are both commands used to remove data from a table, but they have some key differences:
- TRUNCATE: TRUNCATE is a DDL (Data Definition Language) command that quickly removes all rows from a table without logging individual row deletions. It is faster and uses less system resources compared to DELETE. TRUNCATE does not fire triggers and cannot be rolled back.
- DELETE: DELETE is a DML (Data Manipulation Language) command that removes specific rows based on a condition. Unlike TRUNCATE, DELETE logs each row deletion, fires triggers, and can be rolled back using a transaction.
When deciding between TRUNCATE and DELETE, consider the need for transactional control, trigger execution, log space usage, and the performance impact on the system.
Please login or Register to submit your answer