Scope of @@rowcount?

后端 未结 2 1016
北海茫月
北海茫月 2020-12-30 21:06

What is the scope of @@rowcount ?MSDN doesn\'t mention its scope.

Returns the number of rows affected by the last statement.

2条回答
  •  爱一瞬间的悲伤
    2020-12-30 21:35

    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.

提交回复
热议问题