- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如果我有两个表 tableinfo 和 tablenamelist 以及一个外键,如下所示:
Alter tableinfo add foreign key (name) references tablenamelist(name) on update cascade;
什么情况下记录会被修改?
我的理解是,如果我将 tablenamelist 中的“bob”更改为“Bobby”,它会将 tableinfo 中的所有“bob”实例更新为“Bobby”。如果我更改 tableinfo 表中的名称会发生什么?如果我将记录从“bob”更改为“tim”,它会更改表信息中的记录吗?或者它只是将该记录重新分配给新名称?
最佳答案
您的第一个假设是正确的,如果您更改 tablenamelist
中的名称,表 tableinfo
中的名称也会更改。
您的第二个假设是不正确的,如果您尝试将表 tableinfo
中的名称更改为表 tablenamelist
中不存在的名称,您将收到外键违规。
外键是强制外键存在于外表中的约束。
In the context of relational databases, a foreign key is a referential constraint between two tables.
同样来自14.3.5.4. FOREIGN KEY Constraints
InnoDB rejects any INSERT or UPDATE operation that attempts to create a foreign key value in a child table if there is no a matching candidate key value in the parent table.
关于mysql - noob qn 关于更新级联,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13132279/
我是一名优秀的程序员,十分优秀!