Last active
September 4, 2019 07:36
-
-
Save micheletolve/9ce8121662f62d82bb90b72a74895913 to your computer and use it in GitHub Desktop.
DROP table from prefix
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
/** | |
* Delete table in MySQL from theri prefix. | |
*/ | |
DECLARE @prefix VARCHAR(255) = 'mytableprefix' | |
SET GROUP_CONCAT_MAX_LEN=10000; | |
SET @tbls = (SELECT GROUP_CONCAT(TABLE_NAME) | |
FROM information_schema.TABLES | |
WHERE TABLE_SCHEMA = 'my_database' | |
AND TABLE_NAME LIKE @prefix + '_%'); | |
SET @delStmt = CONCAT('DROP TABLE ', @tbls); | |
-- SELECT @delStmt; | |
PREPARE stmt FROM @delStmt; | |
EXECUTE stmt; | |
DEALLOCATE PREPARE stmt; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment