我正試圖創建一個刪除實際記錄之前刪除所有外鍵的觸發器。在SQL Server中刪除觸發器之前
問題是,當我刪除一條記錄時,它會在SQL Server Management Studio中消失,但是當我刷新頁面時,我再次找到它。任何人都知道問題在哪裏?
create Trigger deleteAffaire on AFFAIRE INSTEAD OF DELETE As
begin
Declare @deletedAffaireId int
Declare @deletedPlanId int
set @deletedPlanId = 0;
select @deletedAffaireId = id_affaire from deleted;
begin
select @deletedPlanId = ID_ASSURENCE
from ASSURANCE_QUALITE
where ASSURANCE_QUALITE.ID_AFFAIRE = @deletedAffaireId;
delete from ASSURANCE_CONTACT_FONCTION
where ASSURANCE_CONTACT_FONCTION.ID_ASSURANCE = @deletedPlanId;
delete from JALON
where JALON.ID_JALON in (select ID_JALON from ASSURANCE_JALON_TYPE
where ASSURANCE_JALON_TYPE.ID_ASSURENCE = @deletedPlanId);
delete from ASSURANCE_JALON_TYPE
where ASSURANCE_JALON_TYPE.ID_ASSURENCE = @deletedPlanId;
delete from DOCUMENT
where DOCUMENT.ID_DOCUMENT in (select ID_DOCUMENT from ASSURENCE_DOCUMENT_TYPE
where ASSURENCE_DOCUMENT_TYPE.ID_ASSURENCE = @deletedPlanId);
delete from ASSURENCE_DOCUMENT_TYPE
where ASSURENCE_DOCUMENT_TYPE.ID_ASSURENCE = @deletedPlanId;
delete from ASSURANCE_QUALITE
where ASSURANCE_QUALITE.ID_ASSURENCE = @deletedPlanId;
end
end
你的第一個問題是你的觸發器假設'deleted'只包含1行。這是一個非常破碎的假設。 –