Dropping a Table (Embedded SQL Guide)
Go Up to Dropping Metadata
Use DROP TABLE
to remove a table from a database. A table can only be dropped by its owner, the SYSDBA
, or a user with root privileges. If a table is in use when a drop is attempted, the drop is postponed until the table is no longer in use. The syntax of DROP TABLE
is:
EXEC SQL DROP TABLE name;
<name> is the name of the table to drop. For example, the following statement drops the EMPLOYEE
table:
EXEC SQL DROP TABLE EMPLOYEE; EXEC SQL COMMIT;
Deleting a table fails if a table is used in a view, a trigger, or a computed column. A table cannot be deleted if a UNIQUE
or PRIMARY KEY
integrity constraint is defined for it, and the constraint is also referenced by a FOREIGN KEY
in another table. To drop the table, first drop the FOREIGN KEY
constraints in the other table, then drop the table.
Columns within a table can be dropped without dropping the rest of the table. For more information, see Dropping an Existing Column.
For more information about DROP TABLE
, see the Data Definition Guide.