MSSQL級聯刪除問題

2022-03-22 03:43:25 字數 725 閱讀 2585

現mssql設定級聯刪除時候有個問題,簡單說就是:

乙個表中不能兩次使用外來鍵的級聯刪除或級聯更新。

錯誤提示是:

將 foreign key 約束 'fk_effect.效應例項_effect.效應' 引入表 'effect.效應例項' 中將導致迴圈或多重級聯路徑。請指定 on delete no action 或 on update no action,或修改其它 foreign key 約束。

聯機叢書的解釋是:

由單個 delete 或 update 觸發的一系列級聯引用操作必須構成不包含迴圈引用的樹。在 delete 或 update 所產生的所有級聯引用操作的列表中,每個表只能出現一次。級聯引用操作樹到任何給定表的路徑必須只有乙個。樹的任何分支在遇到指定了 no action 或缺省為 no action 的表時終止。

乙個比較容易想到的辦法是資料庫中用觸發器來實現 on delete cascade,

但是這種方式實現起來的效率可能低一些。

如:code

create

trigger

topic_responses 

ontopic

fordelete

asdelete

responses 

from

responses 

join

deleted 

onresponses.topicid

=deleted.id

SSH級聯刪除問題

1.資料庫有兩張表 department表 和 employee表 department中有外來鍵 did於employee中的did對應.department裡是部門情況。employee是雇員資訊,乙個部門有多條雇員資訊。2.問題是 我刪除一條部門資訊。對應著的該部門也被刪了。而該部門所在的另外...

Mysql中級聯刪除問題

1.對於兩張表 訂單表tb order orderid,訂單與菜表tb order dish orderid,dishid,2.選擇訂單表的orderid作為外來鍵,訂單與菜表的orderid做為子鍵 sql 語句應該為 drop table if exists tb order dish crea...

oracle 級聯刪除

1 查詢外來鍵及父表 select a.constraint name 外鍵名,a.table name 子表,b.table name 父表 from user constraints a,user constraints b where a.constraint type r and b.con...