navigation

TRUNCATE TABLE

The SQL TRUNCATE TABLE statement is used to remove all records from a table in Oracle. It performs the same function as a DELETE statement without a WHERE clause.
NP: If you truncate a table, the TRUNCATE TABLE statement can not be rolled back.
Syntax:
Basic syntax of TRUNCATE TABLE statement is as follows:
TRUNCATE TABLE table_name;

Examples:
Here is the EMPLOYEE1 table:
ID
NAME
START_DATE
END_DATE
SALARY
CITY
1
A
01/01/2016 00:00:00
01/06/2016 00:00:00
10,000
CHENNAI
2
B
02/01/2016 00:00:00
07/03/2016 00:00:00
10,000
BOMBAY
3
C
03/01/2016 00:00:00
08/06/2016 00:00:00
10,000
DELHI
4
D
01/01/2016 00:00:00
07/06/2016 00:00:00
10,000
PUNE
5
E
01/01/2016 00:00:00
09/06/2016 00:00:00
10,000
NOIDA
6
F
01/01/2016 00:00:00
08/06/2016 00:00:00
10,000
BHUBANESWAR
TRUNCATE THE EMPLOYEE1 TABLE:
TRUNCATE TABLE EMPLOYEE1;
This would truncate the table called EMPLOYEE1 and remove all records from that table.
The " EMPLOYEE1" table will now look like this:
ID
NAME
START_DATE
END_DATE
SALARY
CITY
NP:In Oracle, truncating a table is a fast way to clear out records from a table if you don't need to worry about rolling back. One of the reasons is that when the table is truncated, it does not affect any of the table's indexes, triggers, or dependencies. Truncating a table is also a lot easier than dropping the table and recreating it.


No comments:

Post a Comment