MySQL Drop Table

MySQL Drop Table Statement literally drops the existing table from a database. The drop table removes or deletes all the records in a given one along with the structure or definition, and the syntax behind this is

DROP TABLE TableName;
Or 
DROP TABLE Schema_name.TableName;

For this demonstration, we are using the below

Employee Rows 1

MySQL Drop Table Example

In this example, we will delete the empdetails we have shown above.

NOTE: You should be careful while using this statement. You might lose your data and have to recreate the same MySQL table on your own.

DROP TABLE sqltest.empdetails;
Drop Table 2

Let me run the select statement against the table we deleted before. You can see the response, Error Code: 1146

Select Statement to show the rows 3

If you try to remove the one that doesn’t exist, it throws an error. So, for instance, let me delete the already removed one, i.e., empdetails.

If exists 9

From the above screenshot, you can see the error. To avoid this, we can use the IF EXISTS parameter.

DROP TABLE IF EXISTS sqltest.empdetails;
If exists to Check 10

As you see, the above code gives you a warning with a meaningful message.

Using Command Prompt

You can use the MySQL Drop Table statement from the command prompt or Terminal to eliminate it. Here, we delete the employee details and then try to select records from it. As you can see, it was throwing an error.

DROP TABLE sqltest.employeedetails;

SELECT * FROM sqltest.employeedetails;
Using Command Prompt 4

Using Workbench

If you can access the Workbench, it is easy to delete any table. First, right-click on the one you want to delete. i.e., the dim customer. Next, select the Drop.. option.

MySQL Drop Table using Workbench Menu 5

It opens the following pop-up window.

Pop-up Message to Cancel or Continue 6

If you want, you can review the query generated by selecting the Review SQL or clicking on the Drop Now button.

Review Query 7

Let us see the list of them under the sqltest schema.

Available Tables in a schema or Database 8

MySQL Drop Multiple Tables

You must separate those names using a comma to delete more than one. This example deletes multiple tables, such as dim currency and department3.

DROP TABLE IF EXISTS sqltest.dimcurrency, sqltest.department3;

We successfully deleted the two.

MySQL Drop Multiple Table 11