Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drop multiple tables in one shot in MySQL

People also ask

How do I Drop multiple tables at once in SQL?

To drop multiple tables in phpMyAdmin select the page which shows all the tables for a database. Tick the boxes for the tables you want to delete, and select "Drop" from the "With selected:" drop down box. This is shown in the screenshot below where all three tables have been checked: categories, orders and products.

Can you Drop multiple tables in the same statement?

We can drop multiple tables together using a single DROP Table statement as well. Let's create three tables and later we will drop it.

How do I Drop all tables in workbench?

In MySQL Workbench, you can drop all tables pretty easily as well. Select all of the tables in your database in the Schema Browser clicking on the first table, holding Shift, and clicking on the last table. Right-click on the selected tables and select “Drop (n) Tables…”

How do I Drop all tables in a MySQL schema?

MySQL drop all tables from MySQL Workbench Navigate to the Schemas tab. Click on your database name, then click the Tables menu. Click on the first table on the list, then hold SHIFT and click on the last table. With all tables highlighted, right-click on one of the tables and select the drop tables option from the ...


We can use the following syntax to drop multiple tables:

DROP TABLE IF EXISTS B,C,A;

This can be placed in the beginning of the script instead of individually dropping each table.


SET foreign_key_checks = 0;
DROP TABLE IF EXISTS a,b,c;
SET foreign_key_checks = 1;

Then you do not have to worry about dropping them in the correct order, nor whether they actually exist.

N.B. this is for MySQL only (as in the question). Other databases likely have different methods for doing this.


A lazy way of doing this if there are alot of tables to be deleted.

  1. Get table using the below

    • For sql server - SELECT CONCAT(name,',') Table_Name FROM SYS.tables;
    • For oralce - SELECT CONCAT(TABLE_NAME,',') FROM SYS.ALL_TABLES;
  2. Copy and paste the table names from the result set and paste it after the DROP command.