zoukankan      html  css  js  c++  java
  • Access数据库的高效分页

    =========================================
    以下所有分页方法只能用ID排序分页!不能用其他字段。
    //max()分页方法只能根据ID(自增,主键,永远不会重复!),其他字段的话可能会出现重复的值,出现重复的值后用MAX()然后>或<方法就不管用了。
    =========================================
    access数据库以方便携带,容易部署而受到一些小型系统的喜欢

    最近在做一个blogs,因为空间的限制,只能用Access数据库

    测试了一下,当数据量2000+的时候分页比较慢

    我的SQL语句是

    sql = "select top 10 * from tb_article where id not in (select top " + current * 10 + " id from tb_article order by id desc ) order by id desc";

    current 是页码

    随后想到一种:

    sql = "select * from tb_article where id between "+10*current +" and "+10*(current+1) +" order by id desc";

    不过在删除存在的情况下会有问题

    第三种想到的方法:       

    sql = "select top 10 * from tb_article where id >"+current*10 +" order by id desc";

    同样,在删除情况下还是会有问题

    最后又想到一个思路,还是用between

    同时新建一个数据表,里面有三个字段,(页码,首记录ID,尾记录ID)

    每次分页的时候首先查询这个表

    应该速度会加快.

    目前仅在思想中,未测试

    不过此办法比较麻烦,最后使用如下方法

    int total = GetListCount(current);


       sql = "select * from tb_article where id between

    ("+total+"-(SELECT MAX(id)   FROM (SELECT TOP " + (current + 1) * 10 + " id FROM tb_article order by id))+1)

    and

    ("+total+"-(SELECT MAX(id)   FROM (SELECT TOP " + current * 10 + " id FROM tb_article order by id)))

    order by id desc ";

     

  • 相关阅读:
    20070521_新疆出差纪实
    有想应聘技术咨询顾问职位的朋友请看过来
    Access:運作必須查詢3/19
    我們是好朋友1/3
    小說學習1/22
    [Asp.net]動態設定標簽寬度2/22
    [Asp.net]HyperLinkColumn應用2/28
    [Asp.net]重啟IIS2/29
    [Asp.NET]水晶報表與網路密碼2/27
    把學習量化3/6
  • 原文地址:https://www.cnblogs.com/luoyaoquan/p/2062422.html
Copyright © 2011-2022 走看看