问题
I have two after triggers on target table (one for insert and one for update). Now if I execute merge on the target table, the triggers are executed only once. Although the merge statement executes around 300 updates, and 200 inserts.
I checked it with print statements in each trigger, right after getting data from deleted, inserted record into variables.
How come? Is this a bug?
I have SQL Server 2008 sp1 std (part of the SBS2k8).
回答1:
A trigger runs per single action. Not "per row"
You have one insert of 200 rows and one update for 300 rows.
So, the trigger runs once if for insert and update, or the separate triggers run once each
Edit:
- From MSDN, "Multirow Considerations for DML Triggers"
- From Brent Ozar, "Triggers Need to Handle Multiple Records"
来源:https://stackoverflow.com/questions/8486988/merge-statement-and-after-triggers-on-target-table