自引用外键SQL Server DeleteAction无法工作

时间:2021-10-20 00:14:19

I have one Table with a self referencing foreign key with DeleteAction set to Cascade, but when Parent is deleted,no children (direct or descendant) does not delete.

我有一个具有自引用外键的表,其中DeleteAction设置为Cascade,但是当删除Parent时,没有子项(直接或后代)不会删除。

What am I missing ?

我错过了什么?

2 个解决方案

#1


3  

You cannot use cascade delete on self referencing tables.

您不能在自引用表上使用级联删除。

Check this link for possible solution.

检查此链接以获取可能的解决方

#2


-1  

For use delete cascade use following Create table script...

对于使用删除级联使用以下创建表脚本...

CREATE TABLE

test_child

( SUB1 INT, [NO] int, FOREIGN KEY ([NO]) REFERENCES Test_parent ON DELETE CASCADE )

(SUB1 INT,[NO] int,FOREIGN KEY([NO])REFERENCES Test_parent ON DELETE CASCADE)

Check This link for more information:

选中此链接以获取更多信息:

http://msdn.microsoft.com/en-us/library/ms186973.aspx

#1


3  

You cannot use cascade delete on self referencing tables.

您不能在自引用表上使用级联删除。

Check this link for possible solution.

检查此链接以获取可能的解决方

#2


-1  

For use delete cascade use following Create table script...

对于使用删除级联使用以下创建表脚本...

CREATE TABLE

test_child

( SUB1 INT, [NO] int, FOREIGN KEY ([NO]) REFERENCES Test_parent ON DELETE CASCADE )

(SUB1 INT,[NO] int,FOREIGN KEY([NO])REFERENCES Test_parent ON DELETE CASCADE)

Check This link for more information:

选中此链接以获取更多信息:

http://msdn.microsoft.com/en-us/library/ms186973.aspx