I need to make changes to a complex DB with lots of “RESTRICTED” constraints.
Specifically, I need to renumber Id fields in a table UserInfo to which many other tables have Foreign Keys of “RESTICT” on Update and Delete.
I would like to create a script that:
- Finds all the tables with constraints (Foreign Keys) to the “Id” field of “UserInfo” table
- Loads the constraints (Foreign Keys) into a variable
- Alter the dependent table(s) to “Drop” the Foreign Key
- Alter the dependent table(s) to Add a the Foreign Key with “Cascade” on Delete and Update
- … I will insert the update query here …
- Alter the dependent table(s) to “Drop” the Foreign Key
- Alter the dependent table(s) to Add back the original Foreign Key
I just can't figure out how to do step #2, loading the constraint into a variable.
I searched all through the information_schema DB and found the constraint names (i.e. userprefs_ibfk_1). But nowhere does it define what type of constraints they are (i.e. “RESTRICT on Delete”). Is there some secrect code to determining what type of constraint they are?
I might be able to use SHOW CREATE TABLE UserInfo
but I cannot find a way to load the result into a variable (on which I can perform string functions).
I would greatly appreciate any help.