MySQL: How to Enable and Disable Foreign Key Constraint?

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:

To Disable:

To Enable:

At Global level:

To Disable:

To Enable:

Anvesh Patel

Leave a Reply

Be the First to Comment!

Notify of