最精简的分页处理方式

 

 

 

select top 5 * from (select top 15 * from tableNameorder by id asc) tableName order by id desc

 

 

或者类似用select top 方式的分页储存过程

 

 

SQL Server2005 中row_number函数的诞生,在处理分页上简化了很多语句

 

 

row_number函数的用途是非常广泛,这个函数的功能是为查询出来的每一行记录生成一个序号。row_number函数的用法如下面的SQL语句所示:

 

 

没有使用row_number函数

 

SELECT * FROM tableName

 

 

 

 

使用row_number函数

 

 

 

select row_number() over(order by id) as row_number,* from tableName

 

 

 

其中row_number列是由row_number函数生成的序号列。在使用row_number函数是要使用over子句选择对某一列进行排序,然后才能生成序号。

posted @ 2010-04-10 15:48  liuyan  阅读(191)  评论(0编辑  收藏  举报