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
MySQL RESTRICT and NO ACTION
提问by Erebus
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?
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 ACTION
is a deferred check. In MySQL, foreign key constraints are checked immediately, soNO ACTION
is the same asRESTRICT
.
有些数据库系统有延迟检查,并且
NO ACTION
是延迟检查。在 MySQL 中,会立即检查外键约束,因此NO ACTION
与RESTRICT
.
回答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 ACTION
and RESTRICT
is that according to the standard, NO ACTION
is deferred while RESTRICT
acts immediately.
NO ACTION
和之间的区别在于RESTRICT
,根据标准,NO ACTION
是延迟而RESTRICT
立即行动。