0

I want to use @@rowcount to track rows processed. But I have question if one statement is executed and taking long time, meanwhile if other query executed in other query window will it affect @@rowcount value of first one?

How @@rowcount will behave in this scenario?

Database: SQL Server

Dale K
  • 25,246
  • 15
  • 42
  • 71
ADITYA PAWAR
  • 198
  • 2
  • 13
  • What happens when you try it in two windows? – Honeyboy Wilson Mar 25 '20 at 18:59
  • When I'm trying it is giving expected output but I want to use this with dynamic query,So wanted to know firm detail on same. – ADITYA PAWAR Mar 25 '20 at 19:04
  • Does this answer your question? [SQL Server - is using @@ROWCOUNT safe in multithreaded applications?](https://stackoverflow.com/questions/8960510/sql-server-is-using-rowcount-safe-in-multithreaded-applications) – Dale K Mar 25 '20 at 19:15

1 Answers1

2

It will give the corresponding rows affected for the two queries. Two windows here, are effectively two sessions. So they are not affected in any way whatsoever.

@@ROWCOUNT is both scope and connection safe.

In fact, it reads only the last statement row count for that connection and scope. The full rules are here on MSDN (cursors, DML, EXECUTE etc)

To use it in subsequent statements, you need to store it in a local variable.

AswinRajaram
  • 1,519
  • 7
  • 18