Monday, 9 May 2016

Use of @@RowCount function in SQL server ?

To get the total No of Rows affected by the last statement, we can use the system function @@Rowcount in SQL server.

Syntax

@@ROWCOUNT

Example






In the above example, we are assigning the value of @@Rowcount to the int variable.
Based on the value obtained in the variable we are printing the No of Rows.
Instead of assigning the value we can directly check the value using @@Rowcount (e.g If (@@Rowcount > 0))

If the no of rows are more than 2 Billion  then use RowCount_Big. function.

Set NoCount ON statement will not impact the @@Rowcount function.

Note : This @@Rowcount function will return only the no of rows affected by Previous statement.(i.e the Statement before the @@Rowcount function)

No comments:

Post a Comment