问题:@@rowcount 将引用哪个范围?(触发器或 SP)? 解决方案 当然,这篇文章是针对 SQL Server 2000 的,但人们希望版本之间的范围不会改变.根据文章 触发器如何影响 SQL Server 2000 中的 ROWCOUNT 和 IDENTITY, @@ROWCOUNT 不会受到触发器的影响.特别是:即使基表上有触发器,在 SQL Server 2000 中使用 @@ROWCOUNT 也是安全的.触发器不会扭曲您的结果;你会得到你所期望的.即使设置了 NOCOUNT,@@ROWCOUNT 也能正常工作.因此,如果您更新了三行,而触发器在其他地方更新了五行,您将获得 @@ROWCOUNT 为 3.此外,来自 GBN 在 SQL Server 中的回答 - 正在使用@@ROWCOUNT 在多线程应用程序中安全吗?:@@ROWCOUNT 对作用域和连接都是安全的.事实上,它只读取该连接和作用域的最后一条语句行数.What is the scope of @@rowcount ?MSDN doesn't mention its scope.Ok.In my SP — I'm inserting into a table , which has a insert trigger which does another insertion when a new value is inserted to the table.Question:To which scope the @@rowcount will refer ? (trigger or SP) ? 解决方案 Granted, the article is for SQL Server 2000, but one would hope the scope doesn't change between versions. According to the article How triggers affect ROWCOUNT and IDENTITY in SQL Server 2000, @@ROWCOUNT will not be affected by triggers.Specifically:So if you update three rows, and the trigger updates five rows elsewhere, you'll get a @@ROWCOUNT of 3.Also, from GBN's answer in SQL Server - is using @@ROWCOUNT safe in multithreaded applications?: 这篇关于@@rowcount 的范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-26 09:01