bytecounter
bytecounter

Reputation: 133

MySQL Updating/adding foreign key constraints

I have to update foreign constraints in a lot of tables in a lot of databases. The databases should(!) have the same structure, but I realized that there are sometimes little differences (e.g. constraints are different).

So my idea is, to "normalize" all tables by dropping foreign key constraints first.

Is there a way to drop all foreign key constraints referenced to a specified table/column from all tables?

For example:

DROP FOREIGN KEY FROM ... WHERE referenceTable = 'myTable' 
AND referenceCol' = 'myId'

Upvotes: 0

Views: 38

Answers (1)

Pat B
Pat B

Reputation: 1955

I think you need to look here:

http://dev.mysql.com/doc/refman/5.6/en/innodb-information-schema-system-tables.html

It is feasible. Youc could certainly do a single query to drop the keys you need to remove.

Upvotes: 1

Related Questions