三种常用数据库(Oracle、MySQL、SQLServer)的分页之SQLServer
环境 SQLServer 2008 R2 问题 SQLServer 分页 解决 use test;--创建测试表create table test(id int primary key identity,name varchar(20) not null);--插入数据insert into test(name) values('test1');insert into test(name) values('test2');insert in
环境
SQLServer 2008 R2
问题
SQLServer分页
解决
use test; --创建测试表 create table test ( id int primary key identity, name varchar(20) not null ); --插入数据 insert into test(name) values('test1'); insert into test(name) values('test2'); insert into test(name) values('test3'); insert into test(name) values('test4'); insert into test(name) values('test5'); insert into test(name) values('test6'); insert into test(name) values('test7'); insert into test(name) values('test8'); insert into test(name) values('test9'); insert into test(name) values('test10'); select * from test; --执行分页 SELECT TOP 10 id,name FROM test WHERE id NOT IN (SELECT TOP (10 * 0) id FROM test ORDER BY id) ORDER BY ID select id,name from test; --select top pageSize * from tableName where id not in (select top pageSize * (pageNow - 1) id from tableName);
运行效果截图
小技巧
快速插入数据:
insert into test(name) select name from test;
总结语法
SELECT TOP页大小 *
FROM TestTable
WHERE (ID NOT IN
(SELECT TOP页大小 * 页数 id
FROM表
ORDER BY id))
ORDER BY ID
select top pageSize * from tableName where id not in (select top pageSize * (pageNow - 1) id from tableName);
pageNow:当前第几页
pageSize:每页显示的记录数
参考资料
http://android.blog.51cto.com/268543/54310
http://bbs.csdn.net/topics/32008815
上一篇: CSS浮动
下一篇: php中exec函数的用法解决思路
推荐阅读
-
三种常用数据库(Oracle、MySQL、SQLServer)的分页之SQLServer
-
MySQL、SqlServer、Oracle数据库中Alter的用法及区别
-
生成MySQL、SqlServer、Oracle数据的分页话语
-
c#几种数据库的大数据批量插入(SqlServer、Oracle、SQLite和MySql)
-
oracle,mysql,SqlServer三种数据库的分页查询的实例
-
浅谈Mysql、SqlServer、Oracle三大数据库的区别
-
oracle,mysql,SqlServer三种数据库的分页查询的实例
-
Oracle、mysql和sqlserver数据库中对于事务的不同理解
-
SQLServer之常用的分页查询语句介绍
-
sqlserver、Mysql、Oracle三种数据库的优缺点总结