MySQL RESTRICT 和 NO ACTION

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5809954/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 19:40:26  来源:igfitidea点击:

MySQL RESTRICT and NO ACTION

mysqlforeign-keyscascade

提问by Erebus

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

RESTRICT和之间的 MySQL FK 有什么区别NO ACTION?从文档来看,它们看起来完全一样。是这种情况吗?如果是,为什么两者都有?

采纳答案by Anthony Accioly

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

来自 MySQL 文档:https: //dev.mysql.com/doc/refman/8.0/en/create-table-foreign-keys.html

Some database systems have deferred checks, and NO ACTIONis a deferred check. In MySQL, foreign key constraints are checked immediately, so NO ACTIONis the same as RESTRICT.

有些数据库系统有延迟检查,并且NO ACTION是延迟检查。在 MySQL 中,会立即检查外键约束,因此NO ACTIONRESTRICT.

回答by Nanne

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

它符合标准的 SQL 语法。就像手册上说的:(强调我的)

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.

无操作:来自标准 SQL 的关键字。在 MySQL 中,相当于 RESTRICT。如果引用的表中存在相关的外键值,MySQL 服务器将拒绝对父表的删除或更新操作。一些数据库系统有延迟检查,NO ACTION 是延迟检查。在 MySQL 中,立即检查外键约束,因此 NO ACTION 与 RESTRICT 相同。

回答by Wolph

They are identical in MySQL.

它们在 MySQL 中是相同的。

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

在 SQL 2003 标准中,有 5 种不同的引用操作:

CASCADE
RESTRICT
NO ACTION
SET NULL
SET DEFAULT

The difference between NO ACTIONand RESTRICTis that according to the standard, NO ACTIONis deferred while RESTRICTacts immediately.

NO ACTION和之间的区别在于RESTRICT,根据标准,NO ACTION是延迟而RESTRICT立即行动。