如何删除所有相关行 [英] How to delete all dependent rows
问题描述
我有一个表A,它有主键列a,它是B表的外键(表B有主键b和 a 列).表 B 也有一个主键 b,它是 C 表的外键等等.
I have a table A which has primary key column a and it is forigen key to B table(Table B has primary key b and column a).Table B has also a primary key b which forigen key to C table and so on.
现在,如果我想从表 A 中删除一行,那么它不会允许我,因为它的依赖表 B 和表 B 依赖于表 C.所以我必须先从 C 中删除一行,然后是 B,最后是 A 手动
Now if I want to delete a row from Table A then it wont allow me because its dependent table B and table B is dependent on Table C.So I have to delete a row from C first then B and at last A manually
所以有人可以告诉我是否有任何方法可以直接删除而无需去每个表并检查它是否有任何依赖项然后删除
So can anybody please tell me if there is any way to delete directly without going to each table and checking if it has any dependencies or not and then deleting
推荐答案
您可以使用级联 级联引用完整性约束
更新:您应该启用表 B 中表 A (PK) 的级联引用完整性约束,其中 A 的 ID 是外键,类似于表 C 中的表 B 的 PK,其中 B 的 ID 是外键
Update: you should enable Cascading Referential Integrity Constraints of Table A (PK) from Table B where ID of A is foreign Key and similarly of PK of Table B From Table C Where ID of B is foreign Key
非常好的文章 BLOG.SQL 权限
Very Nice Article BLOG.SQL AUTHORITY
这篇关于如何删除所有相关行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!