How to get the number of rows affected in SQL Server (Transact-SQL)?

less than 1 minute read

You can retrieve the no of affected rows using the system variable - ‘@@ROWCOUNT’

Example:

USE MyTestDB;  
GO  
UPDATE Users   
SET Location = N'India'  
WHERE CountryCode = 'IN'  
IF @@ROWCOUNT = 0  
PRINT 'Warning: No rows were updated';  
GO 

Leave a comment