top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to Work with SET ROWCOUNT in SQL Server 2008 using PL/SQL?

0 votes
401 views
How to Work with SET ROWCOUNT in SQL Server 2008 using PL/SQL?
posted Mar 15, 2016 by Sathaybama

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

SET ROWCOUNT is a command which used when we want to retrieve some specific number of rows from a table using PL/SQL.

If we want to get 2 records from the database then we use SET ROWCOUNT before you select statement then also after it make rowcount to 0 other wise next all select commands shows 2 rows only.

Syntax:

SET ROWCOUNT 2

select * from categories

set rowcount 0

Result:

CatID Name Description CreationDate Active

1 Entertainment Entertainment 2009-12-12 1

2 Social Social 2009-10-10 1

Now this command retrieve 2 records only from the database.

This is simple query for this purpose but we use top keyword in query then ROWCOUNT overwrite that keyword e.g.

Syntax:

SET ROWCOUNT 2

select top 3 * from categories

set rowcount 0

Result:

CatID Name Description CreationDate Active

1 Entertainment Entertainment 2009-12-12 1

2 Social Social 2009-10-10 1

We can see in the result that rowcount override the top statement and get only 2 record from the categories table.

answer Mar 15, 2016 by Shivaranjini
...