Skip to main content

DROP TABLE

Drops one or more tables.


Syntax

DROP TABLE [IF EXISTS] <name> [, ...] [CASCADE | RESTRICT]

Description

When you use DROP TABLE to drop a table, you must be the table owner or the owner of the schema to which the table belongs.

DROP TABLE removes not only data recorded in the table but also all related elements including the rules, triggers, and constraints. Therefore, to delete only the data in the table while keeping its definition, use DELETE or TRUNCATE instead.


Parameters

  • IF EXISTS

    If you include IF EXISTS in your command, no error will be reported when the specified table does not exist. A notice will be issued instead.

  • <name>

    The name of the table. You can prefix the name with a schema name to delete the table from the specified schema.

  • CASCADE or RESTRICT

    Whether to drop the table and its dependent objects if dependent objects exist. Supported options include:

    • CASCADE: specifies to drop the dependent objects along with the table.
    • RESTRICT: specifies to reject the drop operation and is the default.

Examples

Drop table test1:

DROP TABLE test1;

SQL standard compatibility

DROP TABLE in Relyt is fully compatible to DROP TABLE in the SQL standard, and DROP TABLE in Relyt provides the following extensions:

  • Allows you to drop more than one table in a single command.
  • Allows you to use the IF EXISTS option.