TRUNCATE vs DELETE in Oracle: Key Differences
In Oracle database, both truncate and delete are used to delete data from a table, but they have some important differences.
- truncate is a DDL statement, whereas delete is a DML statement. Truncate statement immediately releases table space, while delete statement does not. This means that using truncate to delete data from a table will be faster but it cannot be rolled back.
- The truncate statement deletes all data in the entire table, while the delete statement can delete only specific data based on conditions.
- The truncate statement does not trigger triggers on the table, while the delete statement does.
- The truncate statement does not activate the ON DELETE trigger of a table, whereas the delete statement does.
In summary, to delete all data from a table without the option to rollback, you can use the truncate statement. If you need to delete specific data based on conditions or trigger a trigger, then you should use the delete statement.