DELETE vs TRUNCATE: When Does SQL Server Really Clean Up?

2025-10-15 · 2 min

Both commands remove data. But one uses surgical precision, while the other brings a broom. DELETE and TRUNCATE can appear similar — both can leave a table empty. Under the hood, however, SQL Server performs very different operations.

DELETE — the surgeon with a magnifying glass

DELETE operates row by row. Each deleted row is logged in the transaction log, allowing the operation to be rolled back with ROLLBACK.

That provides precision: you can use WHERE, DELETE triggers fire, and foreign-key relationships are respected. But there is a price: log usage increases, and deleting many rows can be expensive.

It is like cleaning up after a party with tweezers — thorough, but slow.

TRUNCATE — the bulldozer operator

TRUNCATE TABLE does not process individual rows in the same way. SQL Server deallocates data pages (8 KB each) and logs allocation changes instead of logging every deleted row.

That is why it is usually fast and uses much less transaction log space.

You cannot add a WHERE clause; DELETE triggers do not fire; and the IDENTITY counter is reset to its seed. Moreover, TRUNCATE requires ALTER permission on the table and is restricted when a foreign key references it.

It is like draining an entire swimming pool — quick, but you cannot leave one fish behind.

Transaction log, backups, and traces of cleanup

Even TRUNCATE is not exempt from transaction logging. Page deallocation records go into the transaction log and can be examined with tools such as fn_dblog().

SQL Server always leaves a trail — smaller, but sufficient for transactional recovery.

From a backup perspective, the difference can be significant:

  • DELETE may generate substantial log records, affecting subsequent log backups.
  • TRUNCATE generally logs much less, making it useful for clearing staging or temporary tables.

“SQL Server remembers more than you think. Even after TRUNCATE, the transaction log contains a trace.”

Bonus for the curious

To see it in action:

1
2
3
4
CREATE TABLE Demo (ID INT IDENTITY, Data CHAR(100));
INSERT INTO Demo (Data) VALUES (REPLICATE('X', 100));
DELETE FROM Demo;
TRUNCATE TABLE Demo;

Then inspect the log:

1
2
3
SELECT [Operation], [Context], [Page ID]
FROM fn_dblog(NULL, NULL)
WHERE [AllocUnitName] LIKE '%Demo%';

For large sets of rows, you can observe far more row-level log activity from DELETE than from TRUNCATE.


In the next installment of our SQL internals series, we will look at ghost records — because even when you think rows have disappeared, SQL Server may only be pretending they are gone.


Tags: SQLServer , TSQL , Performance , Internals , DBA

Marcin Pytlik
LinkedIn · GitHub

Marcin Pytlik

LinkedIn · GitHub