Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.