• λ我爱Aspx >> C#.Net >> 数据库的分页问题_数据库技巧
  • 数据库的分页问题_数据库技巧

  • :aspxer  Դ:internet  :2007-4-28 23:45:19  ؼ:数据库,数据
  • 随着数据库中存储的数据的增多,满足用户查询条件的数据也随之增加。而用户一般不可能一次性看完所有的数据, 很多时候也不需要看完所有数据。在这种情况下,分页返回用户查询的数据就显得相当的重要。分页返回用户数据有如下好处:

    1、减少服务器磁盘系统地读取压力

    2、减少网络流量,减轻网络压力

    3、减轻客户端显示数据的压力

    4、提高处理效率。

    一般而言,分页处理分为两种:应用程序中的分页处理和数据库中的分页处理。目前大多数的应用都是在应用程序中借助支持数据分页处理的数据库访问组件(如DataGrid控件)实现分页处理。实际上,在数据库中实现分页处理,可以从源头减少数据处理量,效果往往可能跟明显。本文主要讨论数据库的分页问题。

    常规的取第n页数据方法为: Select top PageSize * from TableA where Primary_Key not in (select top (n-1)*PageSize Primary_Key from TableA )。

    对于应用程序而言,所做的就是在生成分页处理的T-SQL语句前先计算好各数字, 对于数据库而言,应该采用动态的T-SQL语句。

    以下是使用上述原理实现的通用分页处理存储过程:

    create proc up_PageView

    (

    @tableName sysname,

    @colKey nvarchar(100),

    @pageCurrent int = 1,

    @pageSize int = 10,

    @colShow nvarchar(4000) = '',

    @colOrder nvarchar(200) = '',

    @where nvarchar(2000) = '',

    @pageCount int output

    )

    as

    begin

    if object_id(@tableName) is null

    begin

    raiserror('the table is not existing!', 16,1)

    return

    end

    if isnull(@colShow, '') = ''

    set @colShow = '*'

    if isnull(@colOrder,'') = ''

    set @colOrder = ''

    else

    set @colOrder = 'order by ' + @colOrder

    if isnull(@where, '') = ''

    set @where = ''

    else

    set @where = 'where '+ @where

    declare @sql nvarchar(4000)

    if @pageCount is null

    begin

    set @sql = 'select @pageCount = count(*) from ' + @tableName + ' ' + @where

    Ҷƪл˵?
  • һƪjsp 自定义分页标签_JSP技巧
    һƪGridView 分页导航_ASP.NET技巧