 
exec sp_helptext 'sp_databases' 查看存储过程源代码
在存储过程中,经常用到SET NOCOUNT ON;
作用:阻止在结果集中返回显示受T-SQL语句或则usp影响的行计数信息。 当SET ONCOUNT ON时候,不返回计数,当SET NOCOUNT OFF时候,返回计数;
即使当SET NOCOUNT ON 时候,也更新@@RowCount;
当SET NOCOUNT on时候,将不向客户端发送存储过程每个语句的DONE_IN_proc消息,如果存储过程中包含一些并不返回实际数据的语句,网络通信流量便会大量减少,可以显著提高应用程序性能;
SET NOCOUNT 指定的设置时在执行或运行时候生效,分析时候不生效。


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

创建分页查询存储过程:

查询第一页:

查询第二页:

在存储过程编写时,会一直显示语法错误,原因是在当前sql页面写了其他的语句,它会自动判定执行整个页面的语句,在其上面加个go便不会出现此提示了。(包括创建视图的时候)单独选择执行没问题,如果在该存储过程上面有其他语句,必须加go.
go
create proc usp_getMyStudentsDataByPage
@pagesize int =7,
@pageindex int=1,
@recordcount int output,
@pagecount int output as
begin
select * from (select *,m=ROW_NUMBER() over (order by PersonInfo_id asc) from PersonInfo) as p
where p.m between (@pageindex-1)*@pagesize+1 and @pageindex*@pagesize
set @recordcount=(select count(*) from personinfo)
set @pagecount=ceiling(@recordcount*1.0/@pagesize)
end


sqlserver赋值:


|