SQL Server中存储过程笔记

01.存储过程简述

one.基本语法

create procedure  存储过程名称 --可简写用proc
(
  @参数名1  数据类型,
  @参数名2  数据类型,
  ......
  @参数名n  数据类型 output  --output表示该参数用于输出   
 )
 as 
begin
   执行语句或查询语句等等
 end

two.无参数的存储过程

create proc proc_ memberCount
as  
begin  
   declare @memberCount int  --declare用于声明变量
set  @memberCount= (select COUNT(*) from Student )
   print '班级总人数是:' + cast(@memberCount as nvarchar(20))  
end

three.执行存储过程和删除存储过程

exec 存储过程名称(参数列表) --这是执行存储过程,execute的简写
【例如】:exec proc_ memberCount
drop proc 存储过程名称 --这是删除存储过程,procedure的简写
【例如】drop proc  pro_stuPaging

02.登录存储过程

create proc proc_IsLogin
@userName nvarchar(20),
@userPwd nvarchar(20),
@result int output
as
if exists (select * from Student where StuLoginName=@userName and StuLoginPwd=@userPwd )
begin
set @result=1  --1表示登录成功
end
else
set @result=0   -- 0表示登录失败
go

03.分页存储过程

create procedure pro_stuPaging
 (
    @pageIndex int, --当前页
    @pageSize int,--总页数
	@count int output--总记录数
 )
as
select top (@pageSize)*  
from Student
where StuID not in
(select top (@pageSize*(@pageIndex-1)) StuID from Student)
select  @count=count(*) from Student

exec pro_stuPaging 3, 2,4;--执行存储过程
go

【Moment】:如果出现问题的时候,不那么焦躁,而是冷静解决,这大概就是一次不错的自我存储能量的过程。

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值