Make homepage|Add to favorites
 

MYSQL TOOLS
reviews, articles, tips & snippets

 
Buy SQL » MySQL » Drop multiple tables named with prefix

Drop multiple tables named with prefix

Author: rootsql Date: 7-11-2011, 22:28

Drop multiple tables named with prefix (or named with similar pattern).

 

Generate DELETE statement to delete all tables with prefix 'mng_':

SET @pattern = 'mng_%';
SELECT GROUP_CONCAT(table_schema, '.', table_name) INTO @sql FROM information_schema.tables
  WHERE table_schema = 'database_name' AND table_name LIKE @pattern;
SET @tables = CONCAT('DROP TABLE ', @sql);

 

This code will build a query like this - 'DROP TABLE database_name.mng_table1, database_name.mng_table2, ...'

Run the generated query:

PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
Dear visitor, you went to the site as unregistered user.
We recommend you to Register or Sign In.

Comments:

Leave a comment
Information
Members of Guests cannot leave comments.