In this post, I am providing a script to enable and disable Foreign Key constraint in MySQL.
During data migration and testing purpose, Database Developer requires to disable Foreign key constraint constraint.
Once you disable constraint, later you might require to enable 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:
1 SET FOREIGN_KEY_CHECKS=0;
1 SET FOREIGN_KEY_CHECKS=1;
At Global level:
1 SET GLOBAL FOREIGN_KEY_CHECKS=0;
1 SET GLOBAL FOREIGN_KEY_CHECKS=1;
Please share your ideas and opinions about this topic with me, your contribution will add true value to this topic.
If anyone has doubts on this topic then please do let me know by leaving comments or send me an email.
If you like this post, then please share it with others.
Please follow dbrnd.com, I will share my experience towards the success of Database Research and Development Activity.
I put up a post every day, please keep reading and learning.
Discover Yourself, Happy Blogging !
Anvesh M. Patel.