SQL: deleting tables with prefix

后端 未结 10 1393
后悔当初
后悔当初 2020-11-30 17:27

How to delete my tables who all have the prefix myprefix_?

Note: need to execute it in phpMyAdmin

10条回答
  •  抹茶落季
    2020-11-30 17:59

    I just wanted to post the exact SQL I used - it's something of a mixture of the top 3 answers:

    SET GROUP_CONCAT_MAX_LEN=10000;
    
    SET @del = (
        SELECT      CONCAT('DROP TABLE ', GROUP_CONCAT(TABLE_NAME), ';')
        FROM        information_schema.TABLES
    
        WHERE       TABLE_SCHEMA = 'database_name'
        AND         TABLE_NAME LIKE 'prefix_%'
    );
    
    PREPARE stmt FROM @del;
    EXECUTE stmt;
    DEALLOCATE PREPARE stmt;
    

提交回复
热议问题