简体   繁体   English

MySQL外部约束在DELETE CASCADE上

[英]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 TableParentTableChildAnotherTable

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 TableChildAnotherTable具有一个也称为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一行,则TableChildAnotherTable每一行都将被自动删除。

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.

相关问题 删除级联上的外部约束不起作用 - Foreign constraint On Delete Cascade not working MariaDB / MySQL外键约束:在删除时是否可以请求级联? - MariaDB/MySQL foreign key constraint: possible to request cascade at time of delete? 删除级联上更新级联的外键约束 - foreign key constraint on update cascade on delete cascade MySQL #1452 - 无法添加或更新子行:外键约束失败 ON DELETE CASCADE ON UPDATE CASCADE) - MySQL #1452 - Cannot add or update a child row: a foreign key constraint fails ON DELETE CASCADE ON UPDATE CASCADE) 在MySQL中无限制地强制执行删除级联 - Force a delete cascade with no constraint in MySQL 外键约束On删除级联无效 - Foreign Key Constraint On delete cascade not effective 使用SQLAlchemy删除级联外键约束错误 - Delete cascade foreign key constraint error with SQLAlchemy 如何将 mysql 8 中的约束 FOREIGN KEY 从 laravel 迁移或原始 ZAC5C74B64B4B8352EF2F181AFFB5AC 中的“ON DELETE CASCADE”更改为“ON DELETE SET NULL” - How to change constraint FOREIGN KEY in mysql 8 from `ON DELETE CASCADE` to `ON DELETE SET NULL` in laravel migration or raw sql 如何调试mysql外键约束,ON DELETE CASCADE不能在生产环境中从子表中删除行 - How to debug mysql foreign key constraint, ON DELETE CASCADE not deleting rows from Child table on production environment InnoDB MySql Error 1215无法添加外键约束,即使在删除DELETE的级联义务之后也是如此 - InnoDB MySql Error 1215 Cannot add foreign key constraint / even after removing cascade obligations on DELETE
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM