What is the usage of the truncate command in oracle?

In Oracle, TRUNCATE is a DDL (Data Definition Language) command used to quickly delete all data in a table. The TRUNCATE TABLE statement removes all rows in the table, freeing up storage space, while still keeping the table’s structure, constraints, indexes, and other definitions.

Here is the syntax for TRUNCATE TABLE:

TRUNCATE TABLE table_name;

The table_name is the name of the table from which the data is to be deleted.

Compared to DELETE, TRUNCATE executes faster because it does not delete data row by row, but instead clears the entire table directly. Additionally, TRUNCATE operation does not generate rollback logs, so the deleted operation cannot be rolled back.

It is important to note that when using TRUNCATE TABLE to delete table data, triggers are not executed, and ON DELETE triggers are not activated. On the other hand, the DELETE statement will execute these operations. Therefore, before using TRUNCATE, it is necessary to carefully consider the potential impact on related triggers.

bannerAds