Created
September 8, 2020 17:50
-
-
Save scottopolis/0b57006311a6094a84edf55acf1bc6ea to your computer and use it in GitHub Desktop.
SQL - drop tables based on partial table name
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
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