Search code examples
mysqlsql-drop

MySQL Dropping Tables


What syntax for MySQL would I use to drop multiple tables that have a similar pattern to them? Something like:

DROP TABLES FROM `Database1` LIKE "SubTable*"


Solution

  • No. But you can select tables names from information_schema database:

    select table_name
      from information_schema.tables
     where table_schema = 'Database1'
       and table_name like 'SubTable%'
    

    And after that iterate the table names in result set and drop them