SQL - DROP TABLE Statement
Use the DROP TABLE statement to delete a table with data from the database.
Syntax:
DROP TABLE table_name
The following command will delete the Employee
table in the SQL Server, Oracle, SQLite, PostgreSQL, MySQL database.
DROP TABLE Employee;
DROP Table with Cascade Constraints in Oracle
If the Employee
table has some primary key, which is referred in
other child tables, then first we have to drop referential constraints from the child table and then you
can drop the parent table.
To drop the parent table along with the referential
integrity constraint, you can use the DROP TABLE
command with CASCADE CONSTRAINTS
in Oracle, as shown below.
DROP TABLE Employee CASCADE CONSTRAINTS;
DROP Table with Purge Option in Oracle
If we use DROP TABLE without the PURGE option, it moves the table and its dependent objects to recycle bin, and the space occupied by them will not be freed. If we specify the PURGE option while dropping a table, it will a drop table along with its dependent objects and free the space.
DROP TABLE Employee PURGE;