加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

sql存储过程菜鸟教程

发布时间:2020-12-12 08:02:01 所属栏目:MsSql教程 来源:网络整理
导读:感兴趣的小伙伴,下面一起跟随编程之家 jb51.cc的小编来看看吧。 存储过程是已编译好的T-SQL语句的集合,可以随时调用,速度快,不易出错。但是写长了 确实是很难维护,在项目中我也不怎么喜欢使用。 SQL代码如下: --实例1 --可以传递参数,普通参数和输出参
感兴趣的小伙伴,下面一起跟随编程之家 52php.cn的小编来看看吧。
存储过程是已编译好的T-SQL语句的集合,可以随时调用,速度快,不易出错。但是写长了 确实是很难维护,在项目中我也不怎么喜欢使用。
SQL代码如下:

--实例1   
--可以传递参数,普通参数和输出参数(output)
create proc Newpro
@testVarA int,@testVatB int,@testSum int Output
as
begin
set @testSum=@testVarA+@testVarB
end


--调用存储过程Newpro
declare @testA int
execute Newpro 100,200,@testA output
print @testA


--实例2
create proc testUser
@testUserName varchar(30),@testPassWord varchar(30)
as
begin
declare @testMsg varchar(100)
if @testUserName='user1'
     begin
     if @testPassWord='123'
     set @testMsg='欢迎进入'
     else
     set @testMsg='对不起,密码错误'
     end
else if @testUserName='user2'
     begin
      if @testPassWord='abc'
      set @testMsg='欢迎进入'
      else
      set @testMsg='对不起,密码错误'
     end
else
      set @testMag='请输入正确的用户名'
print @testMsg
end


--调用存储过程testUser
exec testUser 'user1','123'
---- 来自52php.cn 

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读