August 17, 2013

Know that Truncate is DML or DDL in SQL


These are some reason why truncate is ddl not dml

1. TRUNCATE can change storage parameters (the NEXT parameter), and those are part of the object definition - that's in the DDL commands.
2. TRUNCATE does an implicit commit, and cannot be rolled back most DDL operations in Oracle do this, no DML does.that's Truncate is DDL

3. TRUNCATE TABLE handles table as an entity to clear all data from the specified table
4. Deallocates all space used by the removed rows make truncate to DDL
5. The fact that TRUNCATE doesn't run ON DELETE triggers also sets it apart from normal DML operations (but some DML operations also skip triggers, so that's not a clear indicator.

As TRUNCATE removes all rows, it can theoretically be implemented by dropping the table and recreating it in which case it is like any other DDL statement The statement is not expected to be used for usual transactions where insert,update,delete and select statements are used.It is mainly meant for database administration. As it does not manipulate individual rows, it can not be categorized as a DML statement. It is not a DCL statement either. The only remaining option is DDL!

This is complete syntax of Truncate command

TRUNCATE TABLE [schema.] table