September 27, 2005 at 3:22 pm
From logical_io point of view what kind of trigger For Update or After Update is more beneficial when doing bulk update?
I mean, trigger was created on tableA and update column on tableB. For 1 record updated in tableA there is certainly no difference between 2 mentioned trigger types. But in case multiple records updated in tableA (say, bulk)- what is better? Or there is no difference (like number of round trips from tableA to tableB)? Thanks
September 28, 2005 at 1:46 am
No difference between FOR and AFTER
From Books online
A trigger fires only once, no matter how many rows are updated so you should write your trigger in an efficient way and write it to handle any number of records affected.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
September 28, 2005 at 8:36 am
May be I am wrong but the difference is that (from BOL) "AFTER triggers are never executed if a constraint violation occurs" and FOR trigger doesn't care. But, probably, from effeciency point of view there is no difference. Thanks
September 29, 2005 at 12:07 am
AFTER and FOR are synonyms of each other. They create the same trigger. The only types of triggers available in SQL 2000 are AFTER and INSTEAD OF
You can use the FOR clause to specify when a trigger is executed:
The trigger executes after the statement that triggered it completes. If the statement fails with an error, such as a constraint violation or syntax error, the trigger is not executed. AFTER triggers cannot be specified for views, they can only be specified for tables. You can specify multiple AFTER triggers for each triggering action (INSERT, UPDATE, or DELETE). If you have multiple AFTER triggers for a table, you can use sp_settriggerorder to define which AFTER trigger fires first and which fires last. All other AFTER triggers besides the first and last fire in an undefined order which you cannot control.
AFTER is the default in SQL Server 2000. You could not specify AFTER or INSTEAD OF in SQL Server version 7.0 or earlier, all triggers in those versions operated as AFTER triggers.
The trigger executes in place of the triggering action. INSTEAD OF triggers can be specified on both tables and views. You can define only one INSTEAD OF trigger for each triggering action (INSERT, UPDATE, and DELETE). INSTEAD OF triggers can be used to perform enhance integrity checks on the data values supplied in INSERT and UPDATE statements. INSTEAD OF triggers also let you specify actions that allow views, which would normally not support updates, to be updatable.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply