Member-only story

Why TRUNCATE is DDL not DML?

--

Ever wondered why TRUNCATE is classified as a Data Definition Language (DDL) command rather than Data Manipulation Language (DML)? Let's recall the basic differences:

  • Operation: TRUNCATE operates by deallocating the data pages of a table, which is similar to dropping a table and recreating it. It doesn’t delete rows one by one.
  • Transaction Log: TRUNCATE minimally logs the deallocation of data pages, unlike DML commands that log every row change. This minimal logging is characteristic of DDL operations.
  • Identity Reset: In SQL Server and some other databases, TRUNCATE resets identity columns to their seed values, a behavior not associated with DML commands.

These points highlight the structural nature of TRUNCATE, aligning it more with DDL operations that define database structure. A simple mnemonic? TRUNCATE 'trims' the table at a structural level, not just the data within.

--

--

Vengateswaran Arunachalam
Vengateswaran Arunachalam

No responses yet