创建存储过程
无参存储过程
go
if exists(select * from sysobjects where name='存储过程名')
drop procedure 存储过程名
--创建存储过程
create procedure 存储过程名
as
内容体
有参存储过程
在这里插入代码片
go
if exists(select * from sysobjects where name='存储过程名')
drop procedure 存储过程名
--创建存储过程
create procedure 存储过程名(
@变量名1 int --输入参数,用于接收商品类型名称
)
as
内容体
[select * from where id=@变量名1]
调用存储过程
--无参
exec 存储过程名 || execute 存储过程名
--有参
exec 存储过程名 '参数'
创建有输出参数的存储过程 :例子
--判重
go
if exists(select * from sysobjects where name='proc_aaa')
drop procedure proc_aaa、
-- 创建有输出参数的存储过程
go
create procedure proc_aaa(
@type nvarchar(50),
@num int output --使用关键字声明输出参数
)
as
select @num=COUNT(*) from TypeTB where TypeName=@type
***调用***
---调用
go
declare @num int
declare @type nvarchar(20)
set
@type=N'恐怖'
exec proc_aaa @type,@num output
print @num