Does MySQL foreign_key_checks affect the entire database?


The foreign_key_checks are session based. Now, we can say that they are for scope i.e. local or global. Here is an example demo of local or global. Both are scopes and we can set this for session.

Let us set the scope −

mysql> set foreign_key_checks = 0;
Query OK, 0 rows affected (0.00 sec)
mysql> set global foreign_key_checks = 0;
Query OK, 0 rows affected (0.05 sec)

The foreign_key_checks variables are server system variables. Here are some more details −

PropertyValue
System Variableforeign_key_checks
ScopeGlobal, Session
DynamicYes
TypeBoolean
Default ValueON

Setting foreign_key_checks to 0

It affects data definition statements: DROP SCHEMA drops a schema even if it contains tables that have foreign keys that are referred to by tables outside the schema, and DROP TABLE drops tables that have foreign keys that are referred to by other tables.

Setting foreign_key_checks to 1

It does not trigger a scan of the existing table data. Therefore, rows added to the table while foreign_key_checks=0 will not be verified for consistency.

Updated on: 26-Jun-2020

4K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements