Friday 18 November 2016

Is Truncate DDL or DML

It is very tricky question. Truncate releases the memory. In Oracle, PostgreSQL, MySQL it is DDL. So I believe it will be DDL for other RDBMS also. Most of the RDBMS it drops the table and recreate the schema, thus making truncate faster then Delete. Truncate is fast because there is no where clause like delete and also because the data rows still exists in data pages but extent is marked empty for reuse. Truncate don't scan table like in delete, so the process is faster in truncate. Also truncate don't get logged in log file. We can not truncate table where constraint exists, we need to remove constraints, truncate table and again add back the constraint. Truncate will reset the identity column, which means row id will be 1.

No comments:

Post a Comment