Gnanam
Gnanam

Reputation: 10923

Is TRUNCATE a DML statement?

Can we classify/say that TRUNCATE belongs to/falls under DML statement?

Check here for PostgreSQL TRUNCATE compatibility.

NOTE: TRUNCATE is part of SQL standard ANSI SQL 2008 - F200

Upvotes: 3

Views: 2728

Answers (3)

user27624862
user27624862

Reputation: 11

SQL TRUNCATE is a DML. It affects the data in the table but does not affect the structure (definition) of the table. It simply empties the table leaving the structure (definition) intact. So, it 'MANIPILATES' the data in the table-'DATA MANIPULATION LANGUAGE'.

Basically, there are 3 SQL DDLs: CREATE, DROP and ALTER. DDLs affect objects/structures (definition). CREAT creates an object (table). DROP drops an object (table), and ALTER modifies the structure (definition) of the Object. TRUNCATE does none of these, so it is not DDL.

Upvotes: 1

Frank Heikens
Frank Heikens

Reputation: 127297

PostgreSQL

I would say it's a DML statement in PostgreSQL: PostgreSQL has a TRUNCATE trigger but PostgreSQL doesn't have DDL triggers. So it can't be a DDL statement.

It acquires an ACCESS EXCLUSIVE lock on each table it operates on and it's not MVCC-safe but it's transactionsafe and you can do a rollback.

The ability to fire triggers for TRUNCATE is a PostgreSQL extension of the SQL standard.

Upvotes: 4

user330315
user330315

Reputation:

As TRUNCATE manipulates data and does not change any definition, I clearly see it as a DML statement.

Upvotes: 4

Related Questions