Permanently removes a table and all its data from the database.
Syntax
DROP TABLE name [CASCADE | RESTRICT | CASCADE CONSTRAINTS]Description
DROP TABLE permanently removes a table from the database. When you drop a table, all its partitions and subpartitions are also dropped. The statement always removes all indexes, rules, triggers, and constraints associated with the table.
This operation is irreversible. To remove only the rows while keeping the table structure, use DELETE instead.
Behavior with dependent objects:
RESTRICT(default) — returns an error if any other object depends on the table.CASCADEorCASCADE CONSTRAINTS— drops all dependent constraints but not other types of dependent objects for a table.
Parameters
| Parameter | Description |
|---|---|
name | The name of the table to drop. Can be a partitioned table. The name can be schema-qualified. |
CASCADE | Drops all dependent constraints but not other types of dependent objects. |
RESTRICT | Returns an error if the table has dependent objects. This is the default behavior. |
CASCADE CONSTRAINTS | Drops all dependent constraints but not other types of dependent objects. |
Required permissions
To run DROP TABLE, you must be one of the following:
The owner of the partitioning root
A member of a group that owns the table
The schema owner
A database superuser
Examples
Drop a table with no dependent objects
DROP TABLE emp;Drop a table that has dependent objects
Given the following table setup, where items has a foreign key that references orders:
CREATE TABLE orders
(order_id int PRIMARY KEY, order_date date, …)
CREATE TABLE items
(order_id int REFERENCES orders, quantity int, …);The outcome of dropping orders depends on which clause you use:
DROP TABLE orders RESTRICT— returns an error becauseitemsdepends onorders.DROP TABLE orders CASCADE CONSTRAINTS— dropsordersand removes the foreign key constraint fromitems, but leaves theitemstable intact.