SET QUOTED_IDENTIFIER ON GO SET ANSI_NULLS ON GO /**//*存储过程,用于产生10条评论数据*/ -- -- -- -- delete from reviews where operateID>15 -- -- -- -- -- -- -- -- delete from contentinfos where ObjectType=5 ALTERproc Create100Comments as declare@iint declare@ContentIDbigint set@i=1 while@i<=10 begin BEGINTRAN if( @@error!=0 ) goto ErrorHandler committran INSERTINTO[ContentInfos] ( CategoryID,Source, ObjectType,ClickCount, ReviewCount,Grade, VoteCount,CommendCount, AuthorID,BlogID, Size,CollectionTime, IsActive,Keyword, CollectionUser,OriginalID, OriginalURL,F1, F2,F3, F4) VALUES ( 15,'', 5,100, 100,1000, 100,99, 54,204562, 10000,getdate(), 0,'', 'testuser',999, 'testurl',100, 100,'', '') SET@ContentID= IDENT_CURRENT('ContentInfos') INSERTINTO Reviews (CellID , PortalID , UserID , ContentID , OperateTitle , OperateContent , OperateDateTime , BlogID , BlogTitle , OperateUserID , UserName , UserNick , CBlogName , OperateEmail , OperateIP , IsAnonymous , IsActive , OperateHomePage , OperateType , OperateValue ) VALUES(@i, @i, @i, @ContentID, '操作标题', '评
论内容1<br>评论内容2<br>评论内容1<br><br><br><
br>评论内容2<br><br><br><br><br>评论内容2<
br><br><br><br><br>评论内容4<br>', getdate(), @i, 'Blog标题', @i, '用户名称', '用户呢称', 'Blog名称', 'test@126.com', '124.458.135.500', 0, 1, 'http://www.blogcn.com', 1, @i) if( @@error!=0 ) goto ErrorHandler ErrorHandler: if( @@error!=0 ) begin rollbacktran end set@i=@i+1 end GO SET QUOTED_IDENTIFIER OFF GO SET ANSI_NULLS ON GO
2 产生分页的存储过程
SET QUOTED_IDENTIFIER ON GO SET ANSI_NULLS ON GO /**//****** Object: Stored Procedure dbo.CPP_GetTheLastSchoolsWithPage Script Date: 2006-5-11 10:40:08 ******/ /**//* ##SUMMARY 查询一个学校的话题或者活动等 */ -- ##REMARKS Authors :wht Date:2006-6-5 -- ##PARAM @PageSize 页大小 整型INT -- ##PARAM @PageIndex 页索引 整型INT -- ##PARAM @RowCount 总记录数 整型INT --CPP_GetSchoolThemeWithPageNew 10,0,100 createprocedure CPP_Getthesis_thesisWithPageNew ( @PageSizeINT, @PageIndexINT, @RowCountINT ----@whereClauses varchar(1000) ) AS DECLARE@SQLVARCHAR(5000) declare@PageCountint declare@currentPageSizeint --计算总页数 SET@PageCount=CASEWHEN@RowCount%@PageSize=0THEN@RowCount/@PageSizeELSE@RowCount/@PageSize+1END SET@PageIndex=@PageIndex+1 --第一页 IF@PageIndex<=1 BEGIN set@SQL='select SchoolName,t.* from (SELECT top '+cast(@PageSizeasvarchar(10))+' ID, Title, Context, CreateTime, BlogID, AuthorBlogName, Author, Type, IsTop, ReplyCount, ReplyTime, ReplyContext, ReplyBlogID, ReplyBlogName, ReplyNickName, SchoolID, SchoolRegionname FROM School_Themes order by id desc)t inner join school v on t.SchoolID = v.SchoolID order by id desc' END ELSE BEGIN --最后一页 IF@PageIndex>=@PageCountOR@PageIndex<=0 BEGIN set@currentPageSize=@RowCount-(@PageCount-1)*@PageSize if(@currentPageSize<=0) begin set@currentPageSize=@PageSize end SET@SQL='select SchoolName,t.* from (SELECT top '+cast(@PageSizeasvarchar(10))+'ID, Title, Context, CreateTime, BlogID, AuthorBlogName, Author, Type, IsTop, ReplyCount, ReplyTime, ReplyContext, ReplyBlogID, ReplyBlogName, ReplyNickName, SchoolID, SchoolRegionname FROM School_Themes order by id desc)t inner join school v on t.SchoolID = v.SchoolID order by id desc' END ELSE BEGIN --中间页(上) IF@PageIndex>1AND@PageIndex<=@PageCount/2+1 BEGIN SET@SQL=' SELECT TOP '+CONVERT(VARCHAR(15),@PageSize)+' SchoolName, t.* FROM ( SELECT TOP '+CONVERT(VARCHAR(15),@PageSize)+' ID, Title, Context, CreateTime, BlogID, AuthorBlogName, Author, Type, IsTop, ReplyCount, ReplyTime, ReplyContext, ReplyBlogID, ReplyBlogName, ReplyNickName, SchoolID, SchoolRegionname FROM ( SELECT TOP '+CONVERT(VARCHAR(15),@pageSize*@pageIndex)+' ID, Title, Context, CreateTime, BlogID, AuthorBlogName, Author, Type, IsTop, ReplyCount, ReplyTime, ReplyContext, ReplyBlogID, ReplyBlogName, ReplyNickName, SchoolID, SchoolRegionname FROM School_Themes order by id desc )AS A order by id asc )AS t inner join school v on t.SchoolID = v.SchoolID order by id desc' END ELSE --中间页(下) BEGIN SET@SQL='SELECT TOP '+CONVERT(VARCHAR(15),@PageSize)+' shoolName, t.* FROM ( SELECT TOP '+CONVERT(VARCHAR(15),@rowCount-@pageSize*@pageIndex+@pageSize)+' ID, Title, Context, CreateTime, BlogID, AuthorBlogName, Author, Type, IsTop, ReplyCount, ReplyTime, ReplyContext, ReplyBlogID, ReplyBlogName, ReplyNickName, SchoolID, SchoolRegionname FROM School_Themes order by id asc )AS t inner join school v on t.SchoolID = v.SchoolID order id desc ' END END END print@SQL EXEC (@SQL) GO SET QUOTED_IDENTIFIER OFF GO SET ANSI_NULLS ON GO
3、根据存储过程名取存储过程内容
-- 根据存储过程名取存储过程内容 -- 调试 GetContentByProcedureName '[dbo].[CPP_CountOfTrdeByUserID]' alterprocedure GetContentByProcedureName (@ProcedureNamenvarchar(500)) as ifexists (select*from dbo.syscomments where id=object_id(N''+@ProcedureName+'')) select c.text, c.encrypted, c.number, xtype=convert(nchar(2), o.xtype), datalength(c.text), convert(varbinary(8000), c.text), 0from dbo.syscomments c, dbo.sysobjects o where o.id = c.id and c.id =object_id(N''+@ProcedureName+'') orderby c.number, c.colid option(robust plan)
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)