分頁(yè)存儲(chǔ)過(guò)程(用存儲(chǔ)過(guò)程實(shí)現(xiàn)數(shù)據(jù)庫(kù)的分頁(yè)代碼)
更新時(shí)間:2010年06月29日 09:01:31 作者:
用存儲(chǔ)過(guò)程實(shí)現(xiàn)數(shù)據(jù)庫(kù)的分頁(yè)代碼,加快頁(yè)面執(zhí)行速度。具體的大家可以測(cè)試下。
復(fù)制代碼 代碼如下:
--*******************************************************
--* 分頁(yè)存儲(chǔ)過(guò)程 *
--* 撒哈拉大森林 *
--* 2010-6-28 *
--*******************************************************
if exists(select * from sysobjects where type='P' and name=N'P_Paging')
drop procedure P_Paging
go
create procedure P_Paging
@SqlStr nvarchar(4000), --查詢字符串
@CurrentPage int, --第N頁(yè)
@PageSize int --每頁(yè)行數(shù)
as
set nocount on
declare @P1 int, --P1是游標(biāo)的id
@rowcount int
exec sp_cursoropen @P1 output,@SqlStr,@scrollopt=1,@ccopt=1,@rowcount=@rowcount output
select ceiling(1.0*@rowcount/@PageSize) as 總頁(yè)數(shù)--,@rowcount as 總行數(shù),@CurrentPage as 當(dāng)前頁(yè)
set @CurrentPage=(@CurrentPage-1)*@PageSize+1
exec sp_cursorfetch @P1,16,@CurrentPage,@PageSize
exec sp_cursorclose @P1
set nocount off
go
----創(chuàng)建測(cè)試表
--if exists(select * from sysobjects where type='U' and name=N'Test_Students')
-- drop table Test_Students
--go
--create table Test_Students(
-- id int IDENTITY(1,1) not null,
-- name nvarchar(100) not null
--)
--
----創(chuàng)建測(cè)試數(shù)據(jù)
--declare @i int
--set @i = 100000
--while @i>0
-- begin
-- insert into Test_Students values('姓名')
-- set @i = @i - 1
-- end
--
----執(zhí)行存儲(chǔ)過(guò)程
--exec P_Paging 'select * from Test_Students order by id',100,100 --執(zhí)行
--
----刪除測(cè)試表
--if exists(select * from sysobjects where type='U' and name=N'Test_Students')
-- drop table Test_Students
--go
您可能感興趣的文章:
- sqlserver數(shù)據(jù)庫(kù)使用存儲(chǔ)過(guò)程和dbmail實(shí)現(xiàn)定時(shí)發(fā)送郵件
- 用存儲(chǔ)過(guò)程向數(shù)據(jù)庫(kù)存值的具體實(shí)現(xiàn)
- MSSQL監(jiān)控?cái)?shù)據(jù)庫(kù)的DDL操作(創(chuàng)建,修改,刪除存儲(chǔ)過(guò)程,創(chuàng)建,修改,刪除表等)
- sqlSQL數(shù)據(jù)庫(kù)怎么批量為存儲(chǔ)過(guò)程/函數(shù)授權(quán)呢?
- mysql 導(dǎo)入導(dǎo)出數(shù)據(jù)庫(kù)以及函數(shù)、存儲(chǔ)過(guò)程的介紹
- Oracle中 關(guān)于數(shù)據(jù)庫(kù)存儲(chǔ)過(guò)程和存儲(chǔ)函數(shù)的使用
- sql處理數(shù)據(jù)庫(kù)鎖的存儲(chǔ)過(guò)程分享
- SQL Server中通過(guò)擴(kuò)展存儲(chǔ)過(guò)程實(shí)現(xiàn)數(shù)據(jù)庫(kù)的遠(yuǎn)程備份與恢復(fù)
- MSSQL MySQL 數(shù)據(jù)庫(kù)分頁(yè)(存儲(chǔ)過(guò)程)
- 從創(chuàng)建數(shù)據(jù)庫(kù)到存儲(chǔ)過(guò)程與用戶自定義函數(shù)的小感
- SQLserver 數(shù)據(jù)庫(kù)危險(xiǎn)存儲(chǔ)過(guò)程刪除與恢復(fù)方法
- sqlserver關(guān)于分頁(yè)存儲(chǔ)過(guò)程的優(yōu)化【讓數(shù)據(jù)庫(kù)按我們的意思執(zhí)行查詢計(jì)劃】
- mysql 查詢數(shù)據(jù)庫(kù)中的存儲(chǔ)過(guò)程與函數(shù)的語(yǔ)句
- 為數(shù)據(jù)庫(kù)生成某個(gè)字段充填隨機(jī)數(shù)的存儲(chǔ)過(guò)程
- sql 判斷數(shù)據(jù)庫(kù),表,存儲(chǔ)過(guò)程等是否存在的代碼
- Oracle存儲(chǔ)過(guò)程之?dāng)?shù)據(jù)庫(kù)中獲取數(shù)據(jù)實(shí)例
- sqlserver 復(fù)制表 復(fù)制數(shù)據(jù)庫(kù)存儲(chǔ)過(guò)程的方法
- 積分獲取和消費(fèi)的存儲(chǔ)過(guò)程學(xué)習(xí)示例
相關(guān)文章
SQL Server解析XML數(shù)據(jù)的方法詳解
這篇文章主要介紹了SQL Server解析XML數(shù)據(jù)的方法,結(jié)合實(shí)例形式詳細(xì)分析了SQL Server針對(duì)xml數(shù)據(jù)的讀取,遍歷,刪除,查找等常用操作技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2016-06-06SQL Server中查詢結(jié)果超出了查詢時(shí)間范圍解決方法
在本篇文章里小編給大家整理的是關(guān)于SQL Server中查詢結(jié)果超出了查詢時(shí)間范圍解決方法,有需要的朋友們學(xué)習(xí)下。2019-11-11SQL Server日期加減函數(shù)DATEDIFF與DATEADD用法分析
這篇文章主要介紹了SQL Server日期加減函數(shù)DATEDIFF與DATEADD用法,結(jié)合分析SQL Server使用DATEDIFF與DATEADD函數(shù)獲取常見(jiàn)的周、月、天等日期相關(guān)運(yùn)算技巧,需要的朋友可以參考下2017-03-03SQL Server中使用sp_password重置SA密碼實(shí)例
這篇文章主要介紹了SQL Server中使用sp_password重置SA密碼實(shí)例,一般在忘記SA密碼時(shí)的恢復(fù)手段,需要的朋友可以參考下2014-08-08Sqlserver 高并發(fā)和大數(shù)據(jù)存儲(chǔ)方案
本文主要介紹了Sqlserver 高并發(fā)和大數(shù)據(jù)存儲(chǔ)方案。具有一定的參考價(jià)值,下面跟著小編一起來(lái)看下吧2017-01-01MSSQL 將截?cái)嘧址蚨M(jìn)制數(shù)據(jù)問(wèn)題的解決方法
主要原因就是給某個(gè)字段賦值時(shí),內(nèi)容大于字段的長(zhǎng)度或類型不符造成的2010-10-10