Drop all the tables in a schema in Mysql Database
It is often required to delete tables from a MySQL schema. Following is a simple SQL guide that can be used for deleting the all or the specified tables.
1. Turn off the Foreign Key checks
First we need to turn off the foreign key check within the tables. Otherwise, an error would be thrown due to the key constraints.
2. Collect All table names
If the table names are not known, you can query the information_schema table to find them.
SELECT
table_name
FROM
information_schema.tables
WHERE
table_schema = db_name;
3. Drop Each table
Tables can be dropped selectively,
DROP TABLE IF EXISTS ;