SET ROWCOUNT (Transact-SQL)

SQL Server to stop processing the query after the specified number of rows are returned.

To set this option off so that all rows are returned, specify SET ROWCOUNT 0.

Setting the SET ROWCOUNT option causes most Transact-SQL statements to stop processing when they have been affected by the specified number of rows. This includes triggers. The ROWCOUNT option does not affect dynamic cursors, but it does limit the rowset of keyset and insensitive cursors. This option should be used with caution.

SET ROWCOUNT overrides the SELECT statement TOP keyword if the rowcount is the smaller value.

The setting of SET ROWCOUNT is set at execute or run time and not at parse time.

Examples

SET ROWCOUNT stops processing after the specified number of rows. In the following example, It’s result shown 330 rows.

Select * from CandidateMaster WITH(NOLOCK)
Where Email like ‘%gmail.com%’

Here is the result set.

SETRWCnt1

Now, set ROWCOUNT to 5 and return all rows to demonstrate that only 5 rows are returned.

SET ROWCOUNT 5;
Select * from CandidateMaster WITH(NOLOCK)
Where Email like ‘%gmail.com%’

Here is the result set after set rowcount.

SETRWCnt2

THIS TOPIC APPLIES TO: yesSQL Server (starting with 2008)yesAzure SQL DatabaseyesAzure SQL Data Warehouse yesParallel Data Warehouse

If you  want to help to poor student for studing them to click for donation.

Leave a comment

Create a free website or blog at WordPress.com.

Up ↑

Design a site like this with WordPress.com
Get started