DROP TABLE

You are viewing an old version of this article. View the current version here.

Syntax:

DROP [TEMPORARY] TABLE [IF EXISTS] [/*COMMENT TO SAVE*/]
    tbl_name [, tbl_name] ...
    [RESTRICT | CASCADE]

Description:

DROP TABLE removes one or more tables. You must have the DROP privilege for each table. All table data and the table definition are removed, so be careful with this statement! If any of the tables named in the argument list do not exist, MySQL returns an error indicating by name which non-existing tables it was unable to drop, but it also drops all of the tables in the list that do exist.

Important: When a table is dropped, user privileges on the table are not automatically dropped. See GRANT.

Note that for a partitioned table, DROP TABLE permanently removes the table definition, all of its partitions, and all of the data which was stored in those partitions. It also removes the partitioning definition (.par) file associated with the dropped table.

Use IF EXISTS to prevent an error from occurring for tables that do not exist. A NOTE is generated for each non-existent table when using IF EXISTS. See SHOW WARNINGS.

RESTRICT and CASCADE are allowed to make porting easier. In MySQL 5.1, they do nothing.

Since MariaDB 5.5.27 the comment before the tablenames (that /*COMMENT TO SAVE*/) is stored in the binary log. That feature can be used by replication tools to send their internal messages.

Note: DROP TABLE automatically commits the current active transaction, unless you use the TEMPORARY keyword.

Comments

Comments loading...
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.