android – SQLite的“NO ACTION”外键约束究竟做了什么,它与“RESTRICT”的区别如何?

documentation说:

Configuring “NO ACTION” means just that: when a parent key is modified
or deleted from the database, no special action is taken.

我对这句话的第一个解释是“如果父键被修改或删除,那么这个修改就完成了,不采取任何其他行动”,因此不保留数据库的完整性,这导致了一些confusion.
但我的测试显示,如果我尝试删除父键(如果子键仍然存在),我会得到一个异常(“SQLiteConstraintException:错误代码19:约束失败” – 我在android 4.0.3 / SQLite下测试3.7.x),所以“NO ACTION”似乎表现得像预期的那样.

有人可以解释一下,也许举个例子,究竟“无行动”是做什么的,以及它与“限制”的区别.

解决方法:

引言段落说:

If an action is not explicitly specified, it defaults to “NO ACTION”.

这是正常的行动.

此外:

The difference between the effect of a RESTRICT action and normal foreign key constraint enforcement is that the RESTRICT action processing happens as soon as the field is updated – not at the end of the current statement as it would with an immediate constraint, or at the end of the current transaction as it would with a deferred constraint.

如果您使用仅更改一条记录的单语句事务进行测试,则不会看到NO ACTION和RESTRICT之间存在任何差异.

相关文章

SQLite架构简单,又有Json计算能力,有时会承担Json文件/RES...
使用Python操作内置数据库SQLite以及MySQL数据库。
破解微信数据库密码,用python导出微信聊天记录
(Unity)SQLite 是一个软件库,实现了自给自足的、无服务器...
安卓开发,利用SQLite实现登陆注册功能