新客网WWW.XKER.COM:致力做中国最专业的网络学院!
学院: 操作系统 - 网络应用 - 服务器 - 网络安全 - 工具软件 - 办公软件 - Web开发 - 数据库 - 网页设计 - 图形图像 - 媒体动画 - 硬件学堂 - 存储频道 - QQ专区
您的位置:首页 > 软件开发 > 数据库 > 数据库综合 > 正文:分页存储过程

分页存储过程

新客网 XKER.COM 2007-02-05 来源: 收藏本文

create procedure ProgrameName
(@nvar Int,
@pagesize int,
@pageindex int,
@docount bit)
as
set nocount on
if(@docount=1)
select count(num) from TableName where 1=1
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 TableName  where 1=1 order by num desc
select * from TableName O,@indextable t where O.ID=t.nid
and t.id between @PageLowerBound+1 and @PageUpperBound order by t.id
end
set nocount off

-----------------------------------------
如何创建内存临时表?
      
想在内存里创建一个临时表,
--------------------------------------------------------------- 

create  #abc(field1...)即可,可以写成存储过程在delphi中调用 

--------------------------------------------------------------- 

创建一个局部临时表: 

create  table  #tab(id  int  primary  key,name  varchar(10)) 

创建一个全局临时表: 

create  table  ##tab(id  int  primary  key,name  varchar(10)) 

使用表变量: 

declare  @tab  table(id  int,name  varchar(10))

-----------------------------

可以创建临时表。临时表与永久表相似,但临时表存储在 tempdb 中,当不再使用时会自动删除。

有本地和全局两种类型的临时表,二者在名称、可见性和可用性上均不相同。本地临时表的名称以单个数字符号 (#) 打头;它们仅对当前的用户连接是可见的;当用户从 Microsoft SQL Server实例断开连接时被删除。全局临时表的名称以数学符号 (##) 打头,创建后对任何用户都是可见的,当所有引用该表的用户从 SQL Server 断开连接时被删除。

例如,如果创建名为 employees 的表,则任何人只要在数据库中有使用该表的安全权限就可以使用该表,除非它已删除。如果创建名为 #employees 的本地临时表,只有您能对该表执行操作且在断开连接时该表删除。如果创建名为 ##employees 的全局临时表,数据表中的任何用户均可对该表执行操作。如果该表在您创建后没有其他用户使用,则当您断开连接时该表删除。如果该表在您创建后有其他用户使用,则 SQL Server在所有用户断开连接后删除该表。

举例:create table #yangkunjie或者create table ##yangkunjie(全局)

标签:
上一篇:没有了
下一篇:数据库的分页问题
收藏】 【评论】 【推荐】 【投稿】 【打印】 【关闭
发表评论
要记得去论坛讨论,点击注册新会员匿名评论
评论内容:不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
推荐阅读
阅读排行
随机推荐
实用信息推荐