SQL Server 2005中top关键字的用法

1、返回N条记录数

select top n * from <表名> [查询条件]

2、返回总结果集中指定百分比记录数

select top n percent * from <表名> [查询条件]

3、分页查询语句

select top pageSize * from <表名> where [userId] not in(select top startRow [userId] from <表名> order by [userId]) order by userId

pageSize:分页的大小,指定一个页面显示的记录条数,相当于N

startRow:分页起始的记录行号

[userId]:表名的主键

这句话的含义:查询从第startRow条记录起的pageSize条记录数;如果startRow=1,pageSize=10,即查询从第1条记录起的10条记录

原文地址:https://www.cnblogs.com/dazhao/p/3802782.html