This tutorial explains how to use the MySQL DROP TABLE statement with syntax and examples.
The MySQL DROP TABLE statement allows you to remove or delete a table from the MySQL database.
In its simplest form, the syntax for the DROP TABLE statement in MySQL is:
However, the full syntax for the MySQL DROP TABLE statement is:
Optional. It specifies that only temporary tables should be dropped by the DROP TABLE statement.
The name of the table to remove from the database.
The tables to remove from the database, if removing more than one table in the DROP TABLE statement.
Optional. If specified, the DROP TABLE statement will not raise an error if one of the tables does not exist.
Optional. It has no impact or effect on the DROP TABLE statement but is included in the syntax to make porting the tables to different databases easier.
Optional. It has no impact or effect on the DROP TABLE statement but is included in the syntax to make porting the tables to different databases easier.
Let's look at an example that shows how to drop a table using the MySQL DROP TABLE statement.
First, let's look at a simple DROP TABLE example that shows how to use the DROP TABLE statement to drop one table in MySQL.
For example:
This DROP TABLE example would delete the table called customers.
Let's look at an example where we want to drop more than one table using the DROP TABLE statement:
For example:
This DROP TABLE statement example would delete two tables - customers and suppliers. If we were worried that one of the tables doesn't exist and we don't want to raise an error, we could modify our DROP TABLE statement as follows:
This example would delete the customers and suppliers tables and would not raise an error if one of the tables didn't exist.
Finally, let's look at an example that shows how to use the DROP TABLE statement to drop a temporary table.
This DROP TABLE example will only delete the temporary table called customers. If there was also a permanent table called customers, this DROP TABLE statement would not delete it because TEMPORARY is specified.