Skip to content

Instantly share code, notes, and snippets.

@Oleksii909
Created May 8, 2023 14:51
Show Gist options
  • Save Oleksii909/d01a166790eb3d9506e767539fcd0358 to your computer and use it in GitHub Desktop.
Save Oleksii909/d01a166790eb3d9506e767539fcd0358 to your computer and use it in GitHub Desktop.
Delete tables in database started with specific prefixes
-- Set up variable to delete ALL tables starting with 'allane_, default_, dp_, neuwagenabo_'
-- $(drush sql:connect) < drop-tables.sql
-- mysql -u drupal -pdrupal drupal < drop-tables.sql
SET GROUP_CONCAT_MAX_LEN=999999999;
SET @tbls = (SELECT GROUP_CONCAT(TABLE_NAME)
FROM information_schema.TABLES
WHERE TABLE_SCHEMA = 'drupal'
AND (
TABLE_NAME LIKE 'allane_%'
OR TABLE_NAME LIKE 'default_%'
OR TABLE_NAME LIKE 'dp_%'
OR TABLE_NAME LIKE 'neuwagenabo_%'
)
);
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