这篇文章主要为大家详细介绍了sql存储过程菜鸟教程,具有一定的参考价值,可以用来参考一下。

感兴趣的小伙伴,下面一起跟随512笔记的小编罗X来看看吧。

存储过程是已编译好的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'

---- 来自www.512pic

注:关于sql存储过程菜鸟教程的内容就先介绍到这里,更多相关文章的可以留意512笔记的其他信息。

关键词:存储过程

更多推荐

exec php 菜鸟教程,sql存储过程菜鸟教程