Set Rowcount [#] for paging

When talking about paging, beside paging funcion from recordset, what else can do from database to help in paging?

In MSSQL there is a command call ‘SET ROWCOUNT #’, # indicate number of rows return by following querys,

For example:


SELECT COUNT(*) FROM EMPLOYEE   -- Return 25

SET ROWCOUNT 5   -- Set maximum 5 rows return

SELECT * FROM EMPLOYEE   -- 5 rows return

SET ROWCOUNT 0   -- Cancel rowcount, means no limit on rows return

SELECT * FROM EMPLOYEE   -- Now return all 25 rows

I feel this is quite useful when doing paging. Refer to A More Efficient Method for Paging Through Large Result Sets

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s