SQL Server在批处理更新中触发执行 [英] SQL Server trigger execution in batch updating

查看:108
本文介绍了SQL Server在批处理更新中触发执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要了解在以下情况下触发执行的过程。

I need to know about how the trigger execution happens for the below scenario.

我在一个表中有20条记录,并且有一个在该表上执行INSERT,UPDATE 之后触发。当我使用 MERGE 或批处理更新语句更新该表中的所有记录时,触发器将如何执行?

I have 20 records in a table and I have an AFTER INSERT, UPDATE trigger on that table. When I'm updating all the records in that table using a MERGE or batch update statement, how will the trigger execute?

是否逐行执行?

还是每批执行一次(一次全部20条记录)?

Or is it executing once per a batch (once for all 20 records)?

如果每批执行一次,是否需要在触发器内编写一个循环以对每一行执行任务?

If it is execute once per batch do we need to write a loop inside the trigger to perform a task for each row?

推荐答案

SQL Server中的触发器始终执行每批一次-在对于每行触发器中没有选项SQL Server。

Triggers in SQL Server always execute once per batch - there's no option for "for each row" triggers in SQL Server.

批量更新表时,触发器将在 all 更新行。 >已插入和已删除伪表,需要对其进行相应处理-作为一组数据-不是一个行

When you mass-update your table, the trigger will receive all the updated rows at once in the inserted and deleted pseudo tables and needs to deal with them accordingly - as a set of data - not a single row

这篇关于SQL Server在批处理更新中触发执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆