How to disable MySQL foreign key checks and what are the benefits of
disabling it?


We can disable foreign key checks with the help of the following statement −

mysql> Set foreign_key_checks = 0;
Query OK, 0 rows affected (0.00 sec)

And we can enable it with the help of the following statement −

mysql> Set foreign_key_checks = 1;
Query OK, 0 rows affected (0.00 sec)

Some benefits of disabling foreign key checks are as follows −

  • After disabling foreign key checks we can load data into parent and child table in any order. Otherwise, we must have to load the data first in the parent table and then in the child table.
  • Without disabling foreign key checks we cannot drop a table that is referenced by a foreign key constraint.

Updated on: 19-Jun-2020

183 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements