我正在尝试创建一个触发器,在删除实际记录之前删除所有外键。
问题是,当我删除一条记录时,它在 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