Skip to content

Instantly share code, notes, and snippets.

@scottopolis
Created September 8, 2020 17:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scottopolis/0b57006311a6094a84edf55acf1bc6ea to your computer and use it in GitHub Desktop.
Save scottopolis/0b57006311a6094a84edf55acf1bc6ea to your computer and use it in GitHub Desktop.
SQL - drop tables based on partial table name
Using the below as a SQL statement prints out a statement that will drop each table one by one. Copy and paste the statement it prints to drop the tables.
SELECT CONCAT('DROP TABLE ', TABLE_SCHEMA, '.', TABLE_NAME, ';') AS stmt FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME LIKE '%_rg_%' AND TABLE_SCHEMA = 'db_yourdbname' LIMIT 400
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment