Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How do triggers handle multiple updates
Message
De
20/04/2001 17:35:19
 
 
À
20/04/2001 13:57:59
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Stored procedures, Triggers, UDFs
Divers
Thread ID:
00498032
Message ID:
00498161
Vues:
14
Triggers fire once for each manipulation of the table regardless of the number of rows affected. If the one row is affected, the trigger will fire. If five rows are affected, the trigger will fire. If zero (0) rows were affected, the trigger will fire. One of the biggest mistakes developers make is creating triggers that don't support multiple records.

>IF (SELECT somefield FROM inserted)=0
>INSERT INTO sometable ect....

If this code exists in a trigger that fires for a multi-row operation, it will generate an error. Subqueries of this type must return a single value in a single row. To produce the same functionality in a multi-row friendly way, you would need something like this:

INSERT INTO sometable ...
SELECT ...
FROM othertable INNER JOIN inserted
ON inserted.column = othertable.column
WHERE inserted.somefield = 0

-Mike
Michael Levy
MCSD, MCDBA
ma_levy@hotmail.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform