Bonjour,

J'ai deux table contrat et société.

Dans la table contrat j'ai un champ nommé type contrat.

Dans la table société j'ai un autre champ nommé type contrat.

J'ai créé un trigger sous la table contrat qui permet de mettre à jour le champ type contrat dans la table société juste après modification d'une ligne dans la table contrat.

Pour ceci j'ai créé le code suivant :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
USE [RESOCRM]
GO
/****** Object:  Trigger [dbo].[Typecontrat]    Script Date: 03/29/2016 11:35:34 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
ALTER TRIGGER [dbo].[Typecontrat]
   ON  [dbo].[XCONTRAT]
   AFTER update
AS 
BEGIN
 
 
	SET NOCOUNT ON;
 
   declare @typecontrat nvarchar(100)
   declare @societe int
 
 
   select @societe = xcon_companyid from inserted
 
   select @company = comp_companyid from company where comp_companyid = @societe
 
   select @typecontrat = (select xcon_typecontrat  from inserted where xcon_companyid = @societe)
 
 
   update company set comp_typecontrat = @typecontrat  where comp_companyid = @societe
 
 
 
END
J’obtiens la bonne modification dans ma table société mais le problème lorsque j’insère maintenant un nouveau contrat, je trouve q'une nouvelle société a été créé une une autre fois.

Est-ce-qu'il manque un bout de code dans la requête update ?

Merci