Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

Working with SET ROWCOUNT in SQL Server 2008 using PL/SQL

Author: Zunnair

In this simple article you will learn working with SET ROWCOUNT command using PL/SQL in SQL SERVER 2008

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.

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< How we can use Dynamic Management Views(DMV) using Sql Server 2005

Disclaimer - Privacy
© 2002-2017 DevASP.net