sql语句搞分页

本文介绍了一种使用SQL的ROW_NUMBER()函数实现分页查询的方法,并提供了一个存储过程示例。此外,还展示了如何通过创建临时表、清空原始表及重新插入数据来更新表的内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

分页的sql语句:
select * from (select ROW_NUMBER() over(order by UserId)as
 rownum,* from T_UserInfo) t where rownum>3 and rownum<=6


????//调用分页的存储过程
create proc profenye
 @pagesize int,
 @pageindex int
 as
 select * from (select ROW_NUMBER() over(order by UserId)as
 rownum,* from T_UserInfo)t where
 rownum>(@pageindex-1)*@pagesize
 and
 rownum<=@pageindex*@pagesize
 go
 --调用
 exec profenye 3,1

索引:
select distinct * into newtable from T_GRDA
 --删除原表
 delete from T_GRDA WHERE 1=1
 --将临时表数据导入到原表中
 insert into T_GRDA
 SELECT * FROM newtable
 //删除临时表
 drop table newtable

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值