TRUNCATE - ( Oracle Misc )
In Oracle, TRUNCATE
is a command used to remove all rows from a table in a faster way than using the DELETE
statement. It removes all data from a table and resets the high-water mark of the table.
Syntax
The syntax for using the TRUNCATE
command in Oracle is as follows:
TRUNCATE TABLE table_name;
Here, table_name
is the name of the table from which you want to remove all rows.
Example
Consider a table called employees
with columns id
, name
, and salary
. To remove all the rows from this table using TRUNCATE
, we can use the following SQL command:
TRUNCATE TABLE employees;
Output
After executing the TRUNCATE
command, all the rows in the employees
table are deleted, and the table is empty.
Explanation
In the above example, we have used the TRUNCATE
command to remove all the rows from the employees
table in an efficient way. The TRUNCATE
command is much faster than using the DELETE
command because it deallocates space used by the table and resets the high-water mark.
Use
The TRUNCATE
command is useful when you need to remove all rows from a table quickly and efficiently, without removing the table structure. It is particularly helpful when performing large-scale data manipulations, especially in data warehousing and reporting environments.
Important Points
TRUNCATE
is used to remove all rows from a table in Oracle.- It is faster and more efficient than using the
DELETE
statement. - The
TRUNCATE
command deallocates space used by the table and resets the high-water mark. - It is useful for large-scale data manipulations, especially in data warehousing and reporting environments.
Summary
In summary, TRUNCATE
is a command used to remove all rows from a table in Oracle. It is faster and more efficient than using the DELETE
statement because it deallocates space used by the table and resets the high-water mark. The TRUNCATE
command is particularly useful for large-scale data manipulations in data warehousing and reporting environments.