TRUNCATE
and DELETE
commands does the same job, in both the cases data is manipulated, then why does the DELETE
command comes under DML commands and TRUNCATE
command comes under DDL commands?
Asked
Active
Viewed 7,287 times
5

Termininja
- 6,620
- 12
- 48
- 49

Praful Surve
- 788
- 1
- 10
- 22
3 Answers
9
DELETE
- DELETE is a DML Command.
- DELETE statement is executed using a row lock, each row in the table is locked for deletion.
- We can specify filters in where clause
- It deletes specified data if where condition exists.
- Delete activates a trigger because the operation are logged individually.
- Slower than truncate because, it keeps logs.
- Rollback is possible.
TRUNCATE
- TRUNCATE is a DDL command.
- TRUNCATE TABLE always locks the table and page but not each row.
- Cannot use Where Condition.
- It Removes all the data.
- TRUNCATE TABLE cannot activate a trigger because the operation does not log individual row deletions.
- Faster in performance wise, because it doesn't keep any logs.
- Rollback is not possible.

CSK
- 777
- 7
- 17
-
`truncate` _can_ activate a trigger: a "truncate trigger". – Aug 14 '14 at 05:49
-
TRUNCATE is not possible when table has referential keys to other tables. – Wernfried Domscheit Aug 14 '14 at 17:31
5
When we are using Truncate, we are de-allocating the whole space allocated by the data without saving into the undo-table-space. But, in case of Delete, we are putting all the data into undo table-space and then we are deleting all the data. The main points that put TRUNCATE in the DDL camp on Oracle, are:
- TRUNCATE can change storage parameters (the NEXT parameter), and those are part of the object definition - that's in the DDL camp.
- TRUNCATE does an implicit commit, and cannot be rolled back (flashback aside) - most (all?) DDL operations in Oracle do this, no DML does

Raza
- 2,320
- 2
- 22
- 32
2
Well Basically you know the DML AND DDL concept the above difference is just keep in mind but the key difference is that Truncate only manuplates the data without affecting a table structure and key constraints but on the other hand Delete will affect the table with a where conditions.

Aksh
- 654
- 6
- 13
-
how delete will change the table structure if delete all rows from table? – Mansi Raval Dec 19 '19 at 07:32