爱问知识人 爱问教育 医院库

精彩的近乎完美的分页存储过程_PHP教程

首页

精彩的近乎完美的分页存储过程_PHP教程


        

提交回答
好评回答
  • 2023-03-15 23:29:58
    CREATE procedure main_table_pwqzc
    (@pagesize int,
    @pageindex int,
    @docount bit,
    @this_id)
    as
    if(@docount=1)
    begin
    select count(id) from luntan where this_id=@this_id
    end
    else
    begin
    declare @indextable table(id int identity(1,1),nid int)
    declare @PageLowerBound int
    declare @PageUpperBound int
    set @PageLowerBound=(@pageindex-1)*@pagesize
    set @PageUpperBound=@PageLowerBound @pagesize
    set rowcount @PageUpperBound
    insert into @indextable(nid) select id from luntan where this_id=@this_id order by reply_time desc
    select a.* from luntan a,@indextable t where a.id=t.nid
    and t.id>@PageLowerBound and t.id<=@PageUpperBound order by t.id
    end
    GO
    存储过程会根据传入的参数@docount来确定是不是要返回所有要分页的记录总数
    特别是这两行
    set rowcount @PageUpperBound
    insert into @indextable(nid) select id from luntan where this_id=@this_id order by reply_time desc
    真的是妙不可言!set rowcount @PageUpperBound当记录数达到@PageUpperBound时就会停止处理查询
    select id 只把id列取出放到临时表里,select a.* from luntan a,@indextable t where a.id=t.nid
    and t.id>@PageLowerBound and t.id<=@PageUpperBound order by t.id
    而这句也只从表中取出所需要的记录,而不是所有的记录,结合起来,极大的提高了效率!
    妙啊,真的妙!
    CREATE PROCEDURE Paging_RowCount
    (
    @Tables varchar(1000),
    @PK varchar(100),
    @Sort varchar(200) = NULL,
    @PageNumber int = 1,
    @PageSize int = 10,
    @Fields varchar(1000) = '*',
    @Filter varchar(1000) = NULL,
    @Group varchar(1000) = NULL)
    AS
    /*Default Sorting*/
    IF @Sort IS NULL OR @Sort = ''
    SET @Sort = @PK
    /*Find the @PK type*/
    DECLARE @SortTable varchar(100)
    DECLARE @SortName varchar(100)

    http://www.bkjia.com/PHPjc/631236.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/631236.htmlTechArticleCREATE procedure main_table_pwqzc (@pagesize int, @pageindex int, @docount bit, @this_id) as if(@docount=1) begin select count(id) from luntan where this_id=@this_id end else begin.

    韩***

    2023-03-15 23:29:58

类似问题

换一换
  • 电脑/网络 相关知识

  • 电脑网络技术
  • 电脑网络

相关推荐

正在加载...
最新资料 推荐信息 热门专题 热点推荐
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200

热点检索

  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
返回
顶部
帮助 意见
反馈

确定举报此问题

举报原因(必选):