SQL: deleting tables with prefix

后端 未结 10 1394
后悔当初
后悔当初 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:47

    @andre-miller solution is good but there is even better and slightly more professional that will help you execute all in one go. Still will need more than one command but this solution will allow you to use the SQL for automated builds.

    SET @tbls = (SELECT GROUP_CONCAT(TABLE_NAME) 
        FROM information_schema.TABLES
        WHERE TABLE_NAME LIKE 'myprefix_%');
    PREPARE stmt FROM 'DROP TABLE @tbls';
    EXECUTE stmt USING @tbls;
    DEALLOCATE PREPARE stmt;
    

    Note: this code is platform dependant, it's for MySQL but for sure it could be implemented for Postgre, Oracle and MS SQL with slight changes.

提交回复
热议问题