- SELECT
- Order By Rand
- Concat Fields
- Between
- Regexp
- If Null
- Union
- Replace
- Using Syntax
- Substring
- DATE
- Get Date
- Date Format
- Today
- Month Day
- Date Parts
- ADMINISTRATION
- Foreign Key
-
Foreign Key Disable
- Innodb
- Create Database
- Create Table
- Add Column
- Add Index
- Data Type
- Primary Key
- Errors
- Indexes
- Mysqldump
- Table Definition
MYSQL PAGES - LEVEL 3
Disable / enable FK
ALTER TABLE article DISABLE KEYS;
SET FOREIGN_KEY_CHECKS=0;
... do you processing ...
SET FOREIGN_KEY_CHECKS=1;
ALTER TABLE article ENABLE KEYS;
There are two foreign_key_checks variables: a global variable and a local (per session) variable.
Upon connection, the session variable is initialized to the value of the global variable.
The command SET foreign_key_checks modifies the session variable.
To turn off foreign key constraint globally, do the following
SET GLOBAL FOREIGN_KEY_CHECKS=0;
...
SET GLOBAL FOREIGN_KEY_CHECKS=1;
Questions and answers:
Clink on Option to Answer
1. How to temporary disable FK
- a) ALTER TABLE article DISABLE KEYS;
- b) SET FOREIGN_KEYS_CHECKS=1;
2. Turn off FK contraint
- a) SET FOREIGN_KEY_CHECKS = 0;
- b) SET FOREIGN KEY CHECKS = 0;