Remove all foreign keys from MySQL database

I needed to load some lookup data into a MySQL database littered with foreign keys. So I copied the empty DB and ran the output of the following:
[cc lang=’sql’ ]
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 = ‘MY_DATABASE_NAME_HERE’; [/cc]

I loaded the values, and dumped just the values (only insert statements) that I will use to populate the version of the DB with my FK’s intact.

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.