Created
November 18, 2015 15:05
-
-
Save mariolopjr/cb4529237b3c74d4688d to your computer and use it in GitHub Desktop.
Delete all tables in a database that match a specific prefix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Drop all tables with specific prefix | |
* Based on: http://stackoverflow.com/a/24668848 | |
* Modified for my needs | |
* | |
*/ | |
SET @database_name = 'database'; | |
SET @table_prefix = 'prefix%'; | |
SET FOREIGN_KEY_CHECKS = 0; | |
SET GROUP_CONCAT_MAX_LEN = 100000; | |
SELECT * FROM ( | |
SELECT CONCAT('DROP TABLE ', GROUP_CONCAT(TABLE_NAME) , ';') | |
FROM INFORMATION_SCHEMA.TABLES | |
WHERE TABLE_SCHEMA = @database_name AND TABLE_NAME LIKE @table_prefix | |
) a INTO @tbls; | |
PREPARE stmt FROM @tbls; | |
EXECUTE stmt; | |
SET FOREIGN_KEY_CHECKS = 1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment