Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How do triggers handle multiple updates
Message
From
20/04/2001 17:35:19
 
 
To
20/04/2001 13:57:59
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Miscellaneous
Thread ID:
00498032
Message ID:
00498161
Views:
13
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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform