[英]MySQL Foreign Constraint ON DELETE CASCADE
I Want to know if I implemented it right or if it is the other way around. 我想知道我是否正确实施了它,或者相反。
So I have 3 tables: 所以我有3张桌子:
TableParent
, TableChild
and AnotherTable
TableParent
, TableChild
和AnotherTable
TableParent
has a PK called id
TableParent
有一个称为id
的PK
TableChild
and AnotherTable
has a PK also called id
that is also a FK Constraint to TableParent.id
and it has ON DELETE CASCADE
TableChild
和AnotherTable
具有一个也称为id
的PK,它也是对TableParent.id
的FK约束,并且具有ON DELETE CASCADE
I modeled it thinking that if I delete a row in TableParent
, every row in TableChild
and AnotherTable
will be auto deleted. 我以为它建模的想法是,如果删除
TableParent
一行,则TableChild
和AnotherTable
每一行都将被自动删除。
Does it works that way? 这样行吗? (Using MySQL, engine InnoDB)
(使用MySQL和InnoDB引擎)
Was going to post this in a comment, but the comment button is not showing up. 本打算在评论中发布,但评论按钮未显示。
Check out this quesion/answer. 查看此问题/答案。 I think it has all you need and more on this issue.
我认为它拥有您所需的一切,并且在此问题上还有更多。
MySQL foreign key constraints, cascade delete MySQL外键约束,级联删除
I could retype it all, but that seems redundent. 我可以重新输入所有内容,但这似乎很多余。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.