Skip to content

Instantly share code, notes, and snippets.

@bjpeterdelacruz
Created April 26, 2018 00:02
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 bjpeterdelacruz/54a52abe09f694e426052536cd0fc0b4 to your computer and use it in GitHub Desktop.
Save bjpeterdelacruz/54a52abe09f694e426052536cd0fc0b4 to your computer and use it in GitHub Desktop.
How to generate DROP TABLE statements for tables that begin with a certain prefix
-- Generate DROP TABLE statements for tables that begin with "ap_form_"
SELECT CONCAT('DROP TABLE `', TABLE_NAME, '`;') AS queries
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME LIKE 'ap_form_%'
-- Sample output:
-- DROP TABLE `ap_form_10792`;
-- DROP TABLE `ap_form_10792_review`;
-- DROP TABLE `ap_form_11763`;
-- DROP TABLE `ap_form_11763_review`;
-- DROP TABLE `ap_form_14547`;
-- DROP TABLE `ap_form_14547_review`;
-- DROP TABLE `ap_form_15515`;
-- DROP TABLE `ap_form_15515_review`;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment