DROP TABLE

Use the DROP TABLE command to remove an existing table from a database.

Syntax

Syntax dropping a table:
DROP TABLE <table>[,<table>…] [IF EXISTS]

Input

The DROP TABLE command takes the following input:
Table 1. DROP TABLE input
Input Description
<table> The name of the table to be dropped.
IF EXISTS If the specified table name does not exist in the current database and schema, the DROP TABLE command does not throw an error. Unless other conditions such as dependencies prevented the drop operation, the command returns a DROP TABLE message even though it did not drop a table. This option causes the command to ignore the failure condition when the table does not exist.

This option is typically used for scripted applications that are running SQL commands, and you want to suppress the "table not found" error message so that it does not impact or halt the application.

Outputs

The DROP TABLE command has the following outputs:
Table 2. DROP TABLE outputs
Output Description
DROP TABLE The table was successfully dropped.
ERROR: Relation "name" does not exist The specified table does not exist in the database. If you specify IF EXISTS, this error condition is ignored. The command appears to complete successfully even though it did not drop a table.

Privileges

You must be the admin user, the owner of the user, or your account must have the Drop privilege for the user who is the owner of the table or for the User object class.

Usage

The following provides sample usage.
  • To drop the tables films and distributors:
    MYDB.SCH1(USER)=> DROP TABLE films, distributors;