Skip to content

Instantly share code, notes, and snippets.

@anytizer
Created December 28, 2013 06:50
Show Gist options
  • Save anytizer/8156775 to your computer and use it in GitHub Desktop.
Save anytizer/8156775 to your computer and use it in GitHub Desktop.
Improved SQL
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