SQLServer大量数据高效率分页
2016-04-21 19:34
429 查看
以下为从大数据量表检索分页数据的有效方法 测试时,先从LargeTable表选出1000条记录分页呈现
--TIME_SEGMENT为数据表字段
declare @pagesize int--每页大小
declare @currentpage int--当前页
set @pagesize=2
set @currentpage=1
SELECT TOP (@pagesize) *
FROM (
SELECT ROW_NUMBER() OVER (ORDER BY h_job_id) AS id,COUNT(*) OVER() AS TOTAL,*
FROM h_job
where name='周一'
) as t
WHERE t.id > (@pagesize*(@currentpage-1))
order by t.id;
测试结果,百万级的没有索引的表,为5s左右.
http://www.cnblogs.com/85538649/archive/2011/08/13/2137277.html
--TIME_SEGMENT为数据表字段
declare @pagesize int--每页大小
declare @currentpage int--当前页
set @pagesize=2
set @currentpage=1
SELECT TOP (@pagesize) *
FROM (
SELECT ROW_NUMBER() OVER (ORDER BY h_job_id) AS id,COUNT(*) OVER() AS TOTAL,*
FROM h_job
where name='周一'
) as t
WHERE t.id > (@pagesize*(@currentpage-1))
order by t.id;
测试结果,百万级的没有索引的表,为5s左右.
sql ROW_NUMBER() 排序函数请参考一下网址
http://www.cnblogs.com/85538649/archive/2011/08/13/2137277.html
相关文章推荐
- 修改 oracle xe 字符集 ZHS16GBK
- percona mysql 5.7再centerOS 7上的安装
- 认识——数据库存储过程和游标
- sql server触发器
- Oracle 系统表
- Redis主从备份以及key的过期时间配置
- Windows下安装apache+php7+redis扩展
- Oracle内置表二
- 跟我学REDIS-REDIS(五)----常用数据类型之SortedSet
- Memcached 使用记录(以及解决数据不同步的问题的方案)
- Redis数据库安装部署
- MySql设计规范
- 2013 - Lost connection to MySQL server at ‘reading initial communication packet’, system error: 0
- Oracle内置表一
- mysql substring_index substring left right方法
- Oracle 数据导入导出 imp/exp
- openstack数据库获取一个虚机的floating_ip, fix_ip, project_name, user_name, hostname, host
- 通过Navicat for MySQL远程连接的时候报错mysql 1130
- MySql数据类型转化-CAST与CONVERT 函数的用法
- mysql数据库每日定时自动备份