Blog

Use of ROWCOUNT

By Sandeep Singh Shekhawat Blogs | SQL Dec 09, 2012
This blog explains that what is use of ROWCOUNT.

Introduction:

ROWCOUNT uses to stop processing the query after the specified number of rows is returned means its returned rows by query as Top keyword in sql.

Data for Query:

SELECT Id,Name,SALARY FROM EMPLOYEE

empData.PNG

Use Top Keyword:

Query uses top keyword to return specified number of rows.

SELECT TOP 5 Id,Name,SALARY FROM EMPLOYEE

empTopData.PNG

Use RowCOUNT:

DECLARE @NoOfRows INT = 5

SET ROWCOUNT @NoOfRows

SELECT Id,Name,SALARY FROM EMPLOYEE

Here ROWCOUNT uses to stop processing the query after the specified number of rows is returned. When we use  more than one select statement then both select statement will work according to ROWCOUNT means both select statement will have effect of ROWCOUNT and both select statement will return fix according to ROWCOUNT.

empTopData.PNG

Use @@ROWCOUNT:

It returns number of affected rows by last statement  but it does not return this value to client.

DECLARE @NoOfRows INT = 5

SET ROWCOUNT @NoOfRows

SELECT Id,Name,SALARY FROM EMPLOYEE

SELECT @@ROWCOUNT AS [Number Of Rows]

noOfrows.PNG

COMMENT USING

PREMIUM SPONSORS

Hire Mobile & Web Developer on demand. 100% satisfaction. Try for 1 week or Money Back. Local and remote developers available all over USA.

Latest Blogs