This article is half-done without your Comment! *** Please share your thoughts via Comment ***
In this post, I am sharing a script on how to enable and disable Foreign Key constraint in MySQL.
During data migration and testing purpose, Database Developer requires disabling Foreign key constraint.
Once you disable the constraint, later you might require enabling again, but during this exercise make sure that all your data changes are correct, and as per the constraint rule otherwise, you cannot enable those constraints. It violates data integrity rules.
You can perform disable/enable for both global and session levels of MySQL.
At Session level:
To Disable:
1 SET FOREIGN_KEY_CHECKS=0;To Enable:
1 SET FOREIGN_KEY_CHECKS=1;
At Global level:
To Disable:
1 SET GLOBAL FOREIGN_KEY_CHECKS=0;
To Enable:
1 SET GLOBAL FOREIGN_KEY_CHECKS=1;