Reputation: 6471
I need a simple command to remove all tables in my database. Couldn't find it nowhere. Something like
DELETE ALL TABLES of `db1231123`
Upvotes: 1
Views: 4624
Reputation: 350272
How to reset a database in phpMyAdmin
NB: If you recreate the same database objects over and over again, you might want to save the script that is generated in step 6. Then you actually have the SQL to execute the next time you want to remove all tables again.
You could also generate the necessary DROP TABLE
statements with this statement:
SELECT CONCAT('DROP TABLE IF EXISTS ', table_name, ';')
FROM information_schema.tables
WHERE table_schema = 'your-db-name';
Take the output of that query, and put the following SET FOREIGN_KEY_CHECKS
statements around it:
SET FOREIGN_KEY_CHECKS = 0;
-- here come the generated statements, for example:
DROP TABLE IF EXISTS users;
DROP TABLE IF EXISTS companies;
-- ... etc.
--
SET FOREIGN_KEY_CHECKS = 1;
Upvotes: 4