易截截图软件、单文件、免安装、纯绿色、仅160KB

Oracle、SQL Server、Access数据库高效果分页技巧

 在程序的开发过程中,处理分页是大家接触比较频繁的事件,因为现在软件基本上都是与数据库进行挂钓的。但效率又是我们所追求的,如果是像原来那样把所有满足条件的记录全部都选择出来,再去进行分页处理,那么就会多多的浪费掉许多的系统处理时间。为了能够把效率提高,所以现在我们就只选择我们需要的数据,减少数据库的处理时间,以下就是常用SQL分页处理:
  1、SQL Server、Access数据库
  这都微软的数据库,都是一家人,基本的操作都是差不多,常采用如下分页语句:
  PAGESIZE:每页显示的记录数
  CURRENTPAGE:当前页号
  数据表的名字是:components
  索引主键字是:id
以下是引用片段:
  select top PAGESIZE * from components where id not in
  (select top (PAGESIZE*(CURRENTPAGE-1))
  id from components order by id)order by id
  如下列:
以下是引用片段:
  select top 10 * from components where id not in
  (select top 10*10 id from components order by id)
  order by id
  从101条记录开始选择,只选择前面的10条记录
  2、Oracle数据库
  因为Oracle数据库没有Top关键字,所以这里就不能够像微软的数据据那样操作,这里有两种方法:
  (1)、一种是利用相反的。
  PAGESIZE:每页显示的记录数
  CURRENTPAGE:当前页号
  数据表的名字是:components
  索引主键字是:id
以下是引用片段:
  select * from components where id not
  in(select id from components where
  rownum<=(PAGESIZE*(CURRENTPAGE-1)))
  and rownum<=PAGESIZE order by id;
  如下例:
以下是引用片段:
  select * from components where id not in
  (select id from components where rownum<=100)
  and rownum<=10 order by id;
  从101到记录开始选择,选择前面10条。
  (2)、使用minus,即中文的意思就是减去。
以下是引用片段:
  


相关文档:

sql server 内存表

--1加内存表
EXEC sp_tableoption '表名','pintable', 'true' 
--2卸载内存表
EXEC sp_tableoption '表名','pintable', 'false' 
--2查询是否有内存表驻留
SELECT * from INFORMATION_SCHEMA.Tables 
WHERE TABLE_TYPE = 'BASE TABLE' 
          AND OBJECTPROP ......

SQL语句PART5

Confirming granted privileges
Data Dictionary View                Description
ROLE_SYS_PRIVS                System privileges granted to roles
ROLE_TAB_PRIVS    & ......

SQL语句PART9

Group functions
SELECT [column,] group_function(column) ... from table [WHERE condition] [GROUP BY group_by_expression] [ORDER BY column];
e.g.:
SELECT department_id, job_id, SUM(salary), COUNT(employee_id) from employees GROUP BY department_id, job_id ;
SELECT [column,] group_function(column).. ......

SQL语句PART10

oracle tips
Exist的用法:
select gw.ndocid from 
(select ndocid from wf_doc_gw_shouwen union select ndocid from wf_doc_gw_fawen) gw
where
not exists (select null from wf_doc_gw_sn sn where sn.ndocid=gw.ndocid)
2。把GW表和SN表里相同的NDOCID显示出来
select gw.ndocid from 
(se ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号