SQL Server-触发器会影响@@ Rowcount吗? [英] SQL Server - does trigger affects @@Rowcount?
本文介绍了SQL Server-触发器会影响@@ Rowcount吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个查询,该查询会进行UPSERT或更新(如果存在)并插入(如果不存在):
I have a query which do UPSERT or update if exists and insert if not:
update MyTable
set [Name]=@NewValue
where ID=@ID
If @@RowCount = 0
insert into MyTable([Name])
values(@Name)
现在,我想知道 @@ RowCount
是否会受到触发器中执行的查询的影响?让我们说在触发器中,我有:
Now, I wonder if the @@RowCount
will be affected by a query executed in a trigger? Let us say in my trigger I have:
insert into MyLogs(Description)
values("Some description...")
如果在我的第一个查询中更新成功,触发器将向MyLogs运行插入
If the update is successful in my first query, the trigger will run the insert to MyLogs which will have affected rows.
推荐答案
@@ ROWCOUNT
与当前执行的范围,因此不受触发器的影响,触发器将在其他范围内运行。
@@ROWCOUNT
is tied to the scope of your current execution and is therefore unaffected by a trigger, which would run in a different scope.
这篇关于SQL Server-触发器会影响@@ Rowcount吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文