foreign_key_checks
This page is part of MariaDB's Documentation.
The parent of this page is: System Variables for MariaDB Enterprise Server
Topics on this page:
Overview
If set to 1 (the default) foreign key constraints (including ON UPDATE and ON DELETE behavior) InnoDB tables are checked, while if set to 0, they are not checked. 0 is not recommended for normal use, though it can be useful in situations where you know the data is consistent, but want to reload data in a different order from that that specified by parent/child relationships. Setting this variable to 1 does not retrospectively check for inconsistencies introduced while set to 0.
DETAILS
The foreign_key_checks
system variable controls whether foreign key constraints are enabled:
When it is set to
OFF
, foreign key constraints are disabled.When it is set to
ON
, foreign key constraints are enabled.It is not recommended to set this to
OFF
for normal use.It can be useful to set it to
OFF
in situations where you know the data is consistent, but want to reload data in a different order from that that specified by parent/child relationships.When it is set back to
ON
, the server does not retrospectively check for inconsistencies introduced while it was set toOFF
.
The foreign_key_checks
system variable can also affect the performance of ALTER TABLE statements:
In MariaDB Enterprise Server 10.2, when it is set to
OFF
, foreign key constraints can be added to an InnoDB table with theINPLACE
algorithm, which is very efficient. However, no foreign key constraints are checked, which can be unsafe.In MariaDB Enterprise Server 10.3 and later, when it is set to
OFF
, foreign key constraints can be added to an InnoDB table with theNOCOPY
algorithm, which is very efficient. However, no foreign key constraints are checked, which can be unsafe.In all versions of MariaDB Enterprise Server, when it is set to
ON
, foreign key constraints can only be added to an InnoDB table with theCOPY
algorithm, which is much slower. However, foreign key constraints are checked, which can be safer.
PARAMETERS
Command-line | Not Supported |
Configuration file | Not Supported |
Dynamic | Yes |
Scope | Global, Session |
Data Type | BOOLEAN (OFF, ON) |
Product Default Value | ON |
SKYSQL
PRIVILEGES
The foreign_key_checks
system variable requires the SUPER
privilege to dynamically set its global value at runtime.
The foreign_key_checks
system variable does not require any special privilege to dynamically set its session value at runtime.