DF081: @@rowcount is used incorrectly.

The topic describes the DF081 T-SQL code analysis rule.

Category

EXECUTION RULES

Message

@@rowcount is used incorrectly.

Description

It is recommended to use @@ROWCOUNT only after SELECT, INSERT, UPDATE, DELETE or MERGE statements.

Additional information

@@ROWCOUNT returns the number of rows affected by the most recent statement executed in the current session. Using it after DML statements ensures that you get the correct count of affected rows related to the specific operation performed.

@@ROWCOUNT may not provide accurate results if used after other types of statements or if there are multiple statements executed in the session without resetting the @@ROWCOUNT value.

Noncompliant code example

DECLARE @id INT;
IF @@ROWCOUNT > 0
  RETURN;

Compliant solution

UPDATE dbo.DemoTable
SET Name = 'Demo'
WHERE Id = 13;
IF @@ROWCOUNT > 0
  RETURN;