Vous trouverez ci-dessous un déclencheur de mise à jour SQL Server 2005. Pour chaque mise à jour de la table email_subscriberList où l'indicateur isActive change, nous insérons un enregistrement d'audit dans la table email_Events. Cela fonctionne correctement pour les mises à jour simples, mais pour les mises à jour en bloc, seule la dernière ligne mise à jour est enregistrée. Comment puis-je convertir le code ci-dessous pour effectuer une insertion pour chaque ligne mise à jour?Déclencheur de mise à jour SQL Server pour les mises à jour groupées
CREATE TRIGGER [dbo].[Email_SubscriberList_UpdateEmailEventsForUpdate_TRG]
ON [dbo].[Email_subscriberList]
FOR UPDATE
AS
DECLARE @CustomerId int
DECLARE @internalId int
DECLARE @oldIsActive bit
DECLARE @newIsActive bit
DECLARE @email_address varchar(255)
DECLARE @mailinglist_name varchar(255)
DECLARE @email_event_type varchar(1)
SELECT @oldIsActive = isActive from Deleted
SELECT @newIsActive = isActive from Inserted
IF @oldIsActive <> @newIsActive
BEGIN
IF @newIsActive = 1
BEGIN
SELECT @email_event_type = 'S'
END
ELSE
BEGIN
SELECT @email_event_type = 'U'
END
SELECT @CustomerId = customerid from Inserted
SELECT @internalId = internalId from Inserted
SELECT @email_address = (select email from customer where customerid = @CustomerId)
SELECT @mailinglist_name = (select listDescription from Email_lists where internalId = @internalId)
INSERT INTO Email_Events
(mailshot_id, date, email_address, email_event_type, mailinglist_name)
VALUES
(@internalId, getDate(), @email_address, @email_event_type,@mailinglist_name)
END
Comment faites-vous la mise à jour en vrac? – Rup
Plusieurs applications mettront à jour cette table. –