MySQL bulk drop table where table like?

前端 未结 5 2028
暖寄归人
暖寄归人 2020-12-12 21:50
DROP TABLE (
SELECT table_name
FROM information_schema.`TABLES`
WHERE table_schema = \'myDatabase\' AND table_name LIKE BINARY \'del%\');

I know th

5条回答
  •  孤城傲影
    2020-12-12 22:00

    I found it useful to add an IFNULL to Devart's solutions to avoid generating an error if there are no tables matching the query.

    SET @tables = IFNULL(CONCAT('DROP TABLE ', @tables),'SELECT NULL;');
    

提交回复
热议问题