If you specify a SET NULL  action, make sure that you have not declared the columns in the child table as NOT NULL . 

• RESTRICT : Rejects the delete or update operation for the parent table. Specifying RESTRICT  (or NO ACTION ) is the same as omitting the ON DELETE  or ON UPDATE  clause. 

• NO ACTION : A keyword from standard SQL. In MySQL, equivalent to RESTRICT . The MySQL Server rejects the delete or update operation for the parent table if there is a related foreign key value in the referenced table. Some database systems have deferred checks, and NO ACTION  is a deferred check. In MySQL, foreign key constraints are checked immediately, so NO ACTION  is the same as RESTRICT . 

• SET DEFAULT : This action is recognized by the MySQL parser, but both InnoDB  and NDB  reject table definitions containing ON DELETE SET DEFAULT  or ON UPDATE SET DEFAULT  clauses. 

For storage engines that support foreign keys, MySQL rejects any INSERT  or UPDATE  operation that attempts to create a foreign key value in a child table if there is no matching candidate key value in the parent table. 

For an ON DELETE  or ON UPDATE  that is not specified, the default action is always NO ACTION . 

As the default, an ON DELETE NO ACTION  or ON UPDATE NO ACTION  clause that is specified explicitly does not appear in SHOW CREATE TABLE  output or in tables dumped with mysqldump . RESTRICT , which is an equivalent non-default keyword, appears in SHOW CREATE TABLE  output and in tables dumped with mysqldump . 

For NDB  tables, ON UPDATE CASCADE  is not supported where the reference is to the parent table’s primary key. 

As of NDB 8.0.16: For NDB  tables, ON DELETE CASCADE  is not supported where the child table contains one or more columns of any of the TEXT  or BLOB  types. (Bug #89511, Bug #27484882) 

InnoDB  performs cascading operations using a depth-first search algorithm on the records of the index that corresponds to the foreign key constraint. 

A foreign key constraint on a stored generated column cannot use CASCADE , SET NULL , or SET DEFAULT as ON UPDATE  referential actions, nor can it use SET NULL  or SET DEFAULT  as ON DELETE  referential actions. 

A foreign key constraint on the base column of a stored generated column cannot use CASCADE , SET NULL , or SET DEFAULT  as ON UPDATE  or ON DELETE  referential actions. 

## Foreign Key Constraint Examples 

This simple example relates parent  and child  tables through a single-column foreign key: 

CREATE TABLE parent ( id INT NOT NULL, PRIMARY KEY (id) ) ENGINE=INNODB; CREATE TABLE child ( id INT, parent_id INT, INDEX par_ind (parent_id), FOREIGN KEY (parent_id) REFERENCES parent(id) ON DELETE CASCADE ) ENGINE=INNODB; 

