3

I always knew that TRUNCATE is a DDL command but Microsoft documents are confusing me.

This link says that TRUNCATE is a DDL command and this says that TRUNCATE is a DML command

Also, does clarification of DDL and DML are different in different database? Ex. Oracle, MySql etc.

Rubens Farias
  • 55,782
  • 8
  • 132
  • 160
Zerotoinfinity
  • 5,952
  • 31
  • 126
  • 200
  • Possible duplicate: https://stackoverflow.com/questions/26059855/why-is-truncate-a-ddl-statement – MJH Apr 01 '18 at 19:27
  • 1
    Possible duplicate of [How can Delete be both a DDL and a DML statement](https://stackoverflow.com/questions/42536536/how-can-delete-be-both-a-ddl-and-a-dml-statement) – a_horse_with_no_name Apr 01 '18 at 19:30

4 Answers4

2

Personally, I would say that TRUNCATE is a DML command; you're manipulating the data using it, not changing the definition.

There are a few bits on the docs that conflict, mainly as so e are older than others. They can't even decide if CASE is a statement or an expression.

Larnu
  • 76,706
  • 10
  • 34
  • 63
1

Well, TRUNCATE TABLE, as decribed in Microsoft documentation is similar to DELETE (by their own admission). And DELETE is DML, therefore, TRUNCATE TABLE shold be DML as well.

Perhaps the one who wrote the first article did a mistake putting it there. OR perhaps he/she wanted to point out that it's a command to use with the same caution you use for DDL.

I must admit that it's the first time I see that command, and I don't know if it's included in the SQL standard.

1

Wikipedia says TRUNCATE is DML:

In SQL, the TRUNCATE TABLE statement is a Data Manipulation Language (DML) operation that marks the extents of a table for deallocation (empty for reuse). The result of this operation quickly removes all data from a table, typically bypassing a number of integrity enforcing mechanisms. It was officially introduced in the SQL:2008 standard.

https://en.wikipedia.org/wiki/Truncate_(SQL)

MJH
  • 1,670
  • 1
  • 8
  • 18
1

The fact is that TRUNCATE is a DDL command. The first link you provided is correct, the second one was fixed yesterday.

Wikipedia also defines it as a DDL command, but an incorrect edit made on 12 February 2018‎ (and properly reverted on 3 April 2018‎) made it say otherwise for a while.

Marcos Dimitrio
  • 6,100
  • 4
  • 35
  • 59