MySQL RESTRICT and NO ACTION

MysqlForeign KeysCascade

Mysql Problem Overview


What's the difference in a MySQL FK between RESTRICT and NO ACTION? From the doc they seem exactly the same. Is this the case? If so, why have both?

Mysql Solutions


Solution 1 - Mysql

From MySQL Documentation: https://dev.mysql.com/doc/refman/8.0/en/create-table-foreign-keys.html

> 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.

Solution 2 - Mysql

It is to comply with standard SQL syntax. Like the manual says: (emphasis mine)

> 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.

Solution 3 - Mysql

They are identical in MySQL.

In the SQL 2003 standard there are 5 different referential actions:

CASCADE
RESTRICT
NO ACTION
SET NULL
SET DEFAULT

The difference between NO ACTION and RESTRICT is that according to the standard, NO ACTION is deferred while RESTRICT acts immediately.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionErebusView Question on Stackoverflow
Solution 1 - MysqlAnthony AcciolyView Answer on Stackoverflow
Solution 2 - MysqlNanneView Answer on Stackoverflow
Solution 3 - MysqlWolphView Answer on Stackoverflow