我有一個表ParentTable
(id, Name, town
)及其子表human
(mother, father
)其中兩列包含映射到父表。SQL Server 2005外鍵級聯
父表具有town
列,其中包含外鍵引用Town
(townid, townname
),並且該城鎮添加了外鍵引用。
現在的問題是我需要給人表的級聯約束,但在SQL Server多列中爲同一父表不能給出級聯。因此,我創建觸發器這樣,
create trigger DEL_Parent
ON Parent
instead of delete as
set nocount on
delete from human
where mother IN (select id from deleted)
or father IN (select id from deleted)
delete from Parent where id in(select id from deleted).
但是當我嘗試執行觸發時,系統顯示以下錯誤
無法創建,而不是刪除或代替更新觸發 DEL_Parent上表家長。這是因爲該表具有帶級聯刪除或更新的外鍵 鍵。
如何解決問題?提前致謝。
還有什麼可能實現的? – MGPJ 2013-02-28 04:07:52