一.存储过程的基本格式
存储过程的基本格式
【
Create proc 存储过程名
参数列表(定义参数,参数前用@,如果没有参数可以不写,直接写下面的as)
as
begin
存储过程体,存储过程体就是普通的sql语句
end
】
1.无参数形式
Create proc AddUser
as
begin
Insert into T_user(UserName,Age) values(‘xjz’,23)
end
2.有参数形式
(1) 有传入参数的存储过程
Create proc AddUser
@userName varchar(50),
@age int
as
begin
Insert into T_User(UserName,Age) values(@userName,@age)
end
执行有参数的存储过程:
exec 存储过程名 参数列表(用逗号隔开)
如: exec AddUser ‘xjz’,23
(2)有传出参数的存储过程
传出参数要被标记为output
create proc GetUserName
@userName nvarchar(10) output,
@id int
as
begin
select @userName = UserName from T_User where Id = @id
if(@userName<>’’’’)
return1
else
return 0
end