Blog

Use of ROWCOUNT

Posted 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

post comment
     
COMMENT USING
PREMIUM SPONSORS
Over-C is a holistic consortium of communications and technology specialists. We build, deploy and market both business as well as consumer products and solutions.
Get Career Advice from Experts
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.
Join a Chapter