Difficulty
Last Reviewed
Notes
Reference Link
Reviewed
Status
Done
Tags
MySQL DROP TABLE statement syntax
To remove existing tables, you use the MySQL DROP TABLE statement.
Here is the basic syntax of the DROP TABLE statement:
DROP [TEMPORARY] TABLE [IF EXISTS] 
table_name [, table_name] ...
[RESTRICT | CASCADE]- The 
DROP TABLEstatement removes a table and its data permanently from the database. In MySQL, you can also remove multiple tables using a singleDROP TABLEstatement, each table is separated by a comma (,). - The 
TEMPORARYoption allows you to remove temporary tables only. It ensures that you do not accidentally remove non-temporary tables. - The 
IF EXISTSoption conditionally drop a table only if it exists. If you drop a non-existing table with theIF EXISTSoption, MySQL generates a NOTE, which can be retrieved using theSHOW WARNINGSstatement. - Note that the 
DROP TABLEstatement only drops tables. It doesn’t remove specific user privileges associated with the tables. Therefore, if you create a table with the same name as the dropped one, MySQL will apply the existing privileges to the new table, which may pose a security risk. RESTRICT | CASCADE: These are optional keywords that specify what should happen if other tables have foreign key references to the table you're trying to delete.RESTRICTprevents the deletion of the table if there are any references, whileCASCADEdeletes the table and any rows in other tables that reference it.
MySQL DROP TABLE examples
Let’s take some examples of using the DROP TABLE statement.
‣
Using MySQL DROP TABLE to drop a Single Table
‣
Using MySQL DROP TABLE to drop Multiple Tables
‣
Using MySQL DROP TABLE to drop a non-existing table
‣
