Last active
March 4, 2018 01:56
-
-
Save jfriv/7ea2f83831a8f2c8739c91c14e0c7f71 to your computer and use it in GitHub Desktop.
MySQL build query to drop all foreign keys for a table
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
--------------------------------------------------------------------- | |
---- build sql to drop all foreign keys for a table | |
--------------------------------------------------------------------- | |
SELECT CONCAT('ALTER TABLE `',table_schema,'`.`',table_name,'` DROP FOREIGN KEY ',constraint_name,';') | |
FROM information_schema.table_constraints | |
WHERE constraint_type='FOREIGN KEY' | |
AND table_schema='{database}' | |
AND table_name IN ('{table}'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment