SQL Server - does trigger affects @@Rowcount?

半腔热情 提交于 2019-11-27 17:34:05

问题


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)

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...")

If the update is successful in my first query, the trigger will run the insert to MyLogs which will have affected rows.


回答1:


@@ROWCOUNT is tied to the scope of your current execution and is therefore unaffected by a trigger, which would run in a different scope.



来源:https://stackoverflow.com/questions/7005225/sql-server-does-trigger-affects-rowcount

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