The topic describes the DF081 T-SQL code analysis rule.
EXECUTION RULES
@@rowcount is used incorrectly.
It is recommended to use @@ROWCOUNT only after SELECT, INSERT, UPDATE, DELETE or MERGE statements.
@@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.
DECLARE @id INT;
IF @@ROWCOUNT > 0
RETURN;
UPDATE dbo.DemoTable
SET Name = 'Demo'
WHERE Id = 13;
IF @@ROWCOUNT > 0
RETURN;