Note
This variable is available starting with OceanBase Database V2.1.
Description
foreign_key_checks specifies whether to check foreign key constraints in DML/DDL operations.
Applicability
This variable applies only to OceanBase Database in MySQL mode.
Privilege requirements
Query variables
Global level
systenant and all user tenants can execute theSHOW VARIABLESstatement or query theinformation_schema.GLOBAL_VARIABLESview (MySQL mode) to obtain the value of a global system variable.Session level
systenant and all user tenants can execute theSHOW VARIABLESstatement or query theinformation_schema.SESSION_VARIABLESview (MySQL mode) to obtain the value of a session system variable.
Modify variables
Global level
systenant can directly modify the value of a global system variable.MySQL user tenants can modify the value of a global system variable only if they have the
SUPERorALTER SYSTEMprivilege.
Session level
systenant and all user tenants can directly modify the value of a session system variable.
Attributes
| Attribute | Description |
|---|---|
| Type | Boolean |
| Default value | 1 |
| Value range |
|
| Scope |
|
| Modifiable | Yes. You can execute the SET statement to modify the value. |
Usage notes
By default, foreign key constraints are checked in OceanBase Database. You can use the tenant variable foreign_key_checks to enable or disable foreign key constraint checks. If you do not specify a name for a foreign key constraint, the system automatically assigns a constraint name. The automatically assigned constraint name is in the format of table name _OBFK_ creation timestamp. For example, t1_OBFK_1627747200000000.
Examples
Set whether to check foreign key constraints in DML/DDL operations.
Session level
obclient> SET foreign_key_checks = ON;or
obclient> SET foreign_key_checks = 1;Global level
obclient> SET GLOBAL foreign_key_checks = ON;or
obclient> SET GLOBAL foreign_key_checks = 1;
