Oracle TRUNCATE TABLE

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

snippet
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

snippet
TRUNCATE TABLE customers;

Output

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

snippet
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.

Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #
Contents +