Thursday, 24 May 2012

Rowcount (@@rowcount) in Sqlserver

@@rowcount  returns number of rows were after affteced after executing sql query/statement.
If the number of rows is more than 2 billion, use ROWCOUNT_BIG

Syntax :: @@rowcount

Example : 1)  Here it will shows you warning like (Here i  have only)

update [TestApp].[dbo].[UpdatedProducts]
set [ProductID]=4
where [ProductID] =6
if @@rowcount=0
PRINT 'Warning: No rows were updated';
GO

Output :

(0 row(s) affected)
Warning: No rows were updated


2)
here my productId=5 exist in table , so it shows

update [TestApp].[dbo].[UpdatedProducts]
set [ProductID]=4
where [ProductID] =6
if @@rowcount=0
PRINT 'Warning: No rows were updated';
GO

Output :

(1 row(s) affected)

No comments:

Post a Comment