DROP TABLE

Purpose

Use the DROP TABLE statement to move a table or object table to the recycle bin or to remove the table and all its data from the database entirely.

Note: Unless you specify the PURGE clause, the DROP TABLE statement does not result in space being released back to the tablespace for use by other objects, and the space continues to count toward the user’s space quota.

For an external table, this statement removes only the table metadata in the database. It has no affect on the actual data, which resides outside of the database.

When you drop a table that is part of a cluster, the table is moved to the recycle bin. However, if you subsequently drop the cluster, then the table is purged from the recycle bin and can no longer be recovered with a FLASHBACK TABLE operation.

Dropping a table invalidates dependent objects and removes object privileges on the table. If you want to re-create the table, then you must regrant object privileges on the table, re-create the indexes, integrity constraints, and triggers for the table, and respecify its storage parameters. Truncating has none of these effects. Therefore, removing rows with the TRUNCATE statement can be more efficient than dropping and re-creating a table.

When you drop a table, data grants on the object are also dropped.

  <div class="infoboxnote" markdown="1">

  **See Also:**

  - [CREATE TABLE](CREATE-TABLE.html#GUID-F9CE0CC3-13AE-4744-A43C-EAC7A71AAAB6) and [ALTER TABLE](ALTER-TABLE.html#GUID-552E7373-BF93-477D-9DA3-B2C9386F2877) for information on creating and modifying tables

  - [TRUNCATE TABLE](TRUNCATE-TABLE.html#GUID-B76E5846-75B5-4876-98EC-439E15E4D8A4) and [DELETE](DELETE.html#GUID-156845A5-B626-412B-9F95-8869B988ABD7) for information on removing data from a table

  - [FLASHBACK TABLE](FLASHBACK-TABLE.html#GUID-FA9AF2FD-2DAD-4387-9E62-14AFC26EA85C) for information on retrieving a dropped table from the recycle bin

  </div>

Prerequisites

The table must be in your own schema or you must have the DROP ANY TABLE system privilege.

You can perform DDL operations (such as ALTER TABLE, DROP TABLE, CREATE INDEX) on a temporary table only when no session is bound to it. A session becomes bound to a temporary table by performing an INSERT operation on the table. A session becomes unbound to the temporary table by issuing a TRUNCATE statement or at session termination, or, for a transaction-specific temporary table, by issuing a COMMIT or ROLLBACK statement.

Dropping Private Temporary Tables

You can drop a private temporary table using the existing DROP TABLE command. Dropping a private temporary table will not commit an existing transaction. This applies to both transaction-specific and session-specific private temporary tables. Note that a dropped private temporary table will not go into the RECYCLEBIN.

Dropping Blockchain and Immutable Tables

Use the DROP TABLE statement to drop a blockchain or immutable table. It is recommended that you include the PURGE option while dropping these tables. Dropping a blockchain or immutable table removes its definition from the data dictionary, deletes all its rows, and deletes any indexes and triggers defined on the table.

The blockchain or immutable table must be contained in your schema, or you must have the DROP ANY TABLE system privilege.

A blockchain or immutable table can be dropped only after it has not been modified for a period of time that is defined by its retention period.

An empty blockchain or immutable table can be dropped regardless of its retention period.

Syntax

drop_table::=

Description of the illustration drop_table.gif

Semantics

IF EXISTS

Specifying IF EXISTS drops the table if it exists.

Using IF NOT EXISTS with DROP TABLE results in ORA-11544: Incorrect IF EXISTS clause for ALTER/DROP statement.

schema

Specify the schema containing the table. If you omit schema, then Oracle Database assumes the table is in your own schema.

table

Specify the name of the table to be dropped. Oracle Database automatically performs the following operations:

Restrictions on Dropping Tables

CASCADE CONSTRAINTS

Specify CASCADE CONSTRAINTS to drop all referential integrity constraints that refer to primary and unique keys in the dropped table, and all SQL assertions that reference the dropped table.

As with foreign keys the table will not be dropped if there is a SQL assertion referencing it and this clause is omitted.

If you omit this clause, and such referential integrity constraints exist, then the database returns an error and does not drop the table.

PURGE

Specify PURGE if you want to drop the table and release the space associated with it in a single step. If you specify PURGE, then the database does not place the table and its dependent objects into the recycle bin. Note: You cannot roll back a DROP TABLE statement with the PURGE clause, nor can you recover the table if you have dropped it with the PURGE clause.

Using this clause is equivalent to first dropping the table and then purging it from the recycle bin. This clause lets you save one step in the process. It also provides enhanced security if you want to prevent sensitive material from appearing in the recycle bin.

See Also: Oracle Database Administrator’s Guide for information on the recycle bin and naming conventions for objects in the recycle bin

Examples

Dropping a Table: Example

The following statement drops the oe.list_customers table created in “List Partitioning Example”.

DROP TABLE list_customers PURGE;