Created
December 28, 2013 06:50
-
-
Save anytizer/8156775 to your computer and use it in GitHub Desktop.
Improved SQL
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
http://yysource.com/2012/09/mysql-delete-drop-tables-with-prefix/ | |
USE `test`; # Jump to the database | |
SET @table_prefix = '_'; | |
# Load current database into the variable | |
SET @database_name = DATABASE(); | |
SET @tables_to_drop = ( | |
SELECT | |
GROUP_CONCAT(TABLE_NAME) | |
FROM INFORMATION_SCHEMA.TABLES | |
WHERE ( | |
TABLE_SCHEMA = @database_name | |
AND TABLE_NAME LIKE CONCAT(@table_prefix, '%') | |
) | |
); | |
# Did not work? | |
PREPARE drop_tables_statement FROM 'DROP TABLE ?'; | |
EXECUTE drop_tables_statement USING @tables_to_drop; | |
DEALLOCATE PREPARE drop_tables_statement; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment