@@rowcount 的范围是什么?MSDN 没有提到它的范围.
返回受最后一条语句影响的行数.
好的.
在我的 SP - 我插入一个表,它有一个 insert 触发器,当一个新值插入到表中时,它会另一个插入.
问题:
@@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.
Returns the number of rows affected by the last statement.
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:
It’s safe to use @@ROWCOUNT in SQL Server 2000 even when there is a trigger on the base table. The trigger will not skew your results; you’ll get what you expect. @@ROWCOUNT works correctly even when NOCOUNT is set.
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 is both scope and connection safe.
In fact, it reads only the last statement row count for that connection and scope.
更多推荐
@@rowcount 的范围?
发布评论