Truncate Table - (Oracle Query)
In Oracle, TRUNCATE TABLE
is a command that is used to delete all rows from a table. Unlike the DELETE
command, TRUNCATE TABLE
does not log individual row deletions, making it a faster and more efficient way to remove all data from a table.
Syntax
The syntax for using TRUNCATE TABLE
in Oracle is as follows:
TRUNCATE TABLE table_name;
Here, table_name
is the name of the table from which all rows will be deleted.
Example
Suppose we have a table called employees
that contains a list of all employees in a company. We can use the TRUNCATE TABLE
command to remove all employees from the table as shown below:
TRUNCATE TABLE employees;
Output
The output of the TRUNCATE TABLE
command is the deletion of all rows from the table. Any data that was stored in the table before the command was executed will be lost.
Explanation
In the above example, the TRUNCATE TABLE
command is used to delete all rows from the employees
table. This is a faster and more efficient way to remove all data from a table as compared to the DELETE
command, which logs individual row deletions.
Use
The TRUNCATE TABLE
command can be used to remove all data from a table in Oracle. This is useful when the data in a table needs to be deleted and cannot be restored. It is also useful when the table needs to be reloaded with new data.
Important Points
TRUNCATE TABLE
is a faster and more efficient way to remove all data from a table in Oracle.- Unlike the
DELETE
command,TRUNCATE TABLE
does not log individual row deletions. - The
TRUNCATE TABLE
command can only be used on entire tables and not on specific rows. - Once a table has been truncated, the data that was stored in the table before the command was executed will be lost.
Summary
In summary, the TRUNCATE TABLE
command in Oracle is used to delete all rows from a table. It is a faster and more efficient way to remove all data from a table as compared to the DELETE
command. The command should be used with caution as it deletes all data from a table and cannot be undone.