Oracle Truncate Table
Published by : Obay Salah , December 1, 2024
In Oracle, TRUNCATE TABLE statement is used to remove all records from a table. It works same as DELETE statement but without specifying a WHERE clause. It is generally used when you don?t have to worry about rolling back
Once a table is truncated, it can?t be rolled back. The TRUNCATE TABLE statement does not affect any of the table?s indexes, triggers or dependencies.
Syntax
TRUNCATE TABLE [schema_name.]table_name
Parameters
1- schema_name: This parameter specifies the name of the schema that the table belongs to. It is optional.
2- table_name: It specifies the table that you want to truncate.
Oracle TRUNCATE Table Example
Consider a table named "customers" and execute the following query to truncate this
TRUNCATE TABLE customers;
Output
Table truncated. 1.11 seconds
Now check the customers table, you will find that there is no data available in that table. It is equally similar to DELETE TABLE statement in Oracle.
Oracle DELETE Table Example
DELETE TABLE customers;
TRUNCATE TABLE vs DELETE TABLE
Both the statements will remove the data from the "customers" table but the main difference is that you can roll back the DELETE statement whereas you can't roll back the TRUNCATE TABLE statement.
Comments
no comment yet!