---判断是否存在存储过程
if exists( select name from sysobjects where name='proc_name' )
drop proc proc_name
go---创建存储过程
create proc proc_name
@parameter varchar(20),
@parameter2 int
as
主体语句
goif exists:判断是否存在
drop proc : 删除存储过程,后面接存储过程名称,名称不用引起来
create proc: 创建存储过程,后面接存储过程名称,名称不用引起来
@parameter varchar(20): 参数,在执行存储过程的时候需要传入的参数,这里是字符类型,如果有多个参数的话,除了最后一个参数,其他的参数后面需要加逗号(英文状态),如果不需要传入,直接去掉就行了。
create proc proc_name
as
主体语句
goas : 关键字
主体语句:就是你要做的操作的语句,和平时的完全一样,存储过程就相当把平时的sql语句在外面加了个壳的感觉。比如这里你需要查询一个表 select * from tableName1 那么这里就这样写
create proc proc_name
as
select * from tableName1
go
传参数:
create proc proc_name
@parameter varchar(20)
as
select * from tableName where name=@parameter
go
执行的时候这样
exec proc_name '小明'
mysql 存储过程条件判断 sql存储过程判断写法
转载本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
mysql 存储过程 判断 null sql判断存储过程是否存在
判断存储过程是否存在
mysql 存储过程 判断 null 存储过程 表名 Test -
mysql存储过程if多条件判断语句 存储过程中if判断
DB2存储过程——条件判断语句if then
mysql存储过程if多条件判断语句 DB2 sql 执行顺序 存储过程