Updated on 2024-05-07 GMT+08:00

DROP TABLE

Description

Deletes a table.

Precautions

  • After DROP TABLE deletes the table, the indexes depending on the table are deleted, and the functions and stored procedures that need to use this table cannot be executed. Deleting a partitioned table also deletes all partitions in the table.
  • The owner of a table, the owner of the schema of the table, users granted with the DROP permission on the table, or users granted with the DROP ANY TABLE permission can delete the specified table. The system administrator has the permission to delete the specified table by default.
  • When DROP TABLE is executed, if the table to be deleted references another table as a foreign key table, triggers on the referenced table will be deleted in cascading mode. In this case, an eight-level lock needs to be added to the referenced table, which may cause service congestion.

Syntax

DROP TABLE [ IF EXISTS ] 
    { [schema.]table_name } [, ...] [ CASCADE | RESTRICT ] [ PURGE ];

Parameters

  • IF EXISTS

    Reports a notice instead of an error if the specified table does not exist.

  • schema

    Specifies the schema name.

  • table_name

    Specifies the name of the table to be deleted.

  • CASCADE | RESTRICT
    • CASCADE: allows to delete the objects (such as views) that depend on the table.
    • RESTRICT: refuses to delete the table if any objects depend on it. This is the default action.
  • PURGE

    Specifies that even if the recycle bin function is enabled, the table is physically dropped instead of being moved to the recycle bin when you use DROP TABLE to delete tables.

Examples

See Examples in section "CREATE TABLE."

Helpful Links

ALTER TABLE and CREATE TABLE