DROP TABLE (
SELECT table_name
FROM information_schema.`TABLES`
WHERE table_schema = 'myDatabase' AND table_name LIKE BINARY 'del%');
I know this doesn't work! What is the equivalent for something like this in SQL? I can whip out a simple Python script to do this but was just wondering if we can do something with SQL directly. I am using MySQL. Thank you!
A minor improvement to @Devart's answer:
This script should be executed repeatedly until the console's output is
NULL
The changes are:
LIMIT
to avoid the truncation issue I commented aboutselect @tables;
) to have some kind of control when to stop executing the scriptI found it useful to add an IFNULL to Devart's solutions to avoid generating an error if there are no tables matching the query.
If you just need to quickly drop a bunch of tables (not in pure SQL, so not directly answering this question) a one line shell command can do it:
You can use prepared statements -
It will generate and execute a statement like this -