Merge statement and after triggers on target table

混江龙づ霸主 提交于 2019-12-12 14:00:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!