Skip to content

Instantly share code, notes, and snippets.

@micheletolve
Last active September 4, 2019 07:36
Show Gist options
  • Save micheletolve/9ce8121662f62d82bb90b72a74895913 to your computer and use it in GitHub Desktop.
Save micheletolve/9ce8121662f62d82bb90b72a74895913 to your computer and use it in GitHub Desktop.
DROP table from prefix
/**
* 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