Les Trigger ne fonctionne pas avec les relations
Bonjour,
Je developpe une petit GPAO et j'ai 2 tables,entête de facture client (t_FactCli) et Ligne de facture client (TFactCliL) j'ai une relation entre ces 2 tables avec UPDATE et DELETE en cascade.
voir ci après
Code:
1 2 3 4 5 6 7 8 9 10 11
| USE [NEX_DB]
GO
ALTER TABLE [dbo].[T_FactCliL] WITH CHECK ADD CONSTRAINT [FK_T_FactCliL_T_FactCli] FOREIGN KEY([FactCli_Num])
REFERENCES [dbo].[T_FactCli] ([FactCli_Num])
ON UPDATE CASCADE
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[T_FactCliL] CHECK CONSTRAINT [FK_T_FactCliL_T_FactCli]
GO |
Sur la table T_factCliL, j'ai un trigger qui viens mettre à jours le reliquat de facturation dans la table des lignes d'affaire (T_AffL)
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
ALTER TRIGGER [dbo].[Tri_FactCliL_UID] ON [dbo].[T_FactCliL]
AFTER INSERT, UPDATE, DELETE
AS
BEGIN
SET NOCOUNT ON;
--**************************************************************************************
--* Met à jours le reliquat de facturation pour les lignes d'affaires *
--**************************************************************************************
UPDATE T_AffL
SET T_AffL.AffL_QteFactRelicatUStk = T_AffL.AffL_QteFactRelicatUStk - [QteFacturee]
,T_AffL.AffE_Code = case T_AffL.AffL_QteFactRelicatUStk - [QteFacturee] when 0 then 5 else Case when T_Affl.AffL_QteCdeUStk=T_Affl.AffL_QteExpUStk then 4 else Case when T_Affl.AffL_QteExpUStk=0 then 2 else 3 end end end
FROM T_AffL
RIGHT OUTER JOIN (SELECT T_InsDel.*,T_FactCli.FactType_Code FROM (
SELECT isnull(deleted.FactCli_Num,inserted.FactCli_Num) as [FactCli_Num],isnull(deleted.Aff_NUM, inserted.Aff_Num) as [Aff_Num], isnull(deleted.AffL_Num, inserted.AffL_Num) as [AffL_Num], (isnull(inserted.FactCliL_QteUStk,0) - isnull(deleted.FactCliL_QteUStk,0)) as [QteFacturee]
FROM deleted
full outer JOIN inserted ON deleted.Aff_Num = inserted.Aff_Num AND deleted.AffL_Num = inserted.AffL_Num) as T_InsDel
LEFT OUTER JOIN T_FactCli ON T_FactCli.FactCli_Num = T_InsDel.FactCli_Num
WHERE FactType_Code in (2,4)
) as T_Temp
ON T_Temp.[Aff_Num]=T_AffL.Aff_NUM AND T_Temp.[AffL_Num]=T_AffL.AffL_NUM
END |
Mon trigger fonctionne très bien avec des requêtes DELETE, UPDATE, INSERT sur la table T_factCliL mais ne se déclenche pas quand je fait une requête DELETE sur la table T_FACTCLI alors que ma relation efface bien les lignes correspondantes dans la table T_FactCliL :(.
si quelqu'un aurais une piste je serait preneur.
Merci d'avance