本文介绍了MySQL的默认ON DELETE行为是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试解析MySQL 文档.他们可能会更清楚.他们似乎在说的是,有五种可能性:SET NULL,NO ACTION,RESTRICT,CASCADE和SET DEFAULT.

I'm trying to parse the MySQL docs. They could be clearer. What they seem to be saying is that there are five possibilities: SET NULL, NO ACTION, RESTRICT, CASCADE, and SET DEFAULT.

NO ACTION和RESTRICT会执行相同的操作(防止任何破坏FK的数据库更改),并且该操作是默认操作,因此,如果省略ON DELETE子句,则表示NO ACTION(或RESTRICT -是相同的操作).

NO ACTION and RESTRICT do the same thing (prevent any DB change that breaks an FK) and that thing is the default so if you omit an ON DELETE clause you're saying NO ACTION (or RESTRICT -- same thing).

SET NULL允许删除父行,将FK设置为​​NULL.

SET NULL allows a parent row deletion, sets the FK to NULL.

CASCADE删除子行.

CASCADE deletes child row.

SET DEFAULT应该永远不被使用.

SET DEFAULT should just never be used.

这或多或少是正确的吗?

Is this more or less correct?

推荐答案

是的,这是正确的:

限制:拒绝删除或更新 父表的操作. 指定RESTRICT(或NO ACTION)为 等同于省略ON DELETE或 ON UPDATE子句. [...]

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 ACTIONRESTRICT是同义词.此外,由于每当没有ON DELETE / UPDATE子句时都使用它们,因此这是默认行为.

Apparently NO ACTION and RESTRICT are synonymous. Additionally, since they are used whenever there is no ON DELETE / UPDATE clause, this is the default behavior.

外部列设置为NULL,前提是未将其声明为NOT NULL(否则InnoDB将不允许删除或更新).

The foreign column is set to NULL, provided it is not declared as NOT NULL (or InnoDB will not allow deletion or update).

级联删除(或更新)外部列.

Cascade deletes (or updates) the foreign column.

所以基本上您不能使用该选项.

So basically you cannot use that option.

这篇关于MySQL的默认ON DELETE行为是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 14:16
查看更多