存储过程:
create PROCEDURE GetStuInf //创建一个存储过程,将表中Student中的数据放入存储过程中
as
begin
select * from Student
end
ALTER PROCEDURE [dbo].[GetStuInf] //修改一个存储过程,将表Student中ClassName='rrrr'中的数据放入存储数据中
as
begin
select * from Student where ClassName='rrrr'
end
create Procedure GetClass//查询一个带参数的存储过程
@classname nvarchar(50),
@age int
as
begin
select * from Student where ClassName=@classname and Age =@age
end
//存储过程的返回值
create procedure getcc
@class nvarchar(50),
@age int,
@maxscore int output, //申明一个传出参数
@vgescore int output,
@stucount int output
as
begin
select * from Student where ClassName=@class or Age=@age
select @maxscore=MAX(chinese) from Student where ClassName=@class or Age=@age
select @vgescore=AVG(chinese) from Student where ClassName=@class or Age=@age
select @stucount=COUNT(chinese) from Student where ClassName=@class or Age=@age
end
//通过return返回值
alter procedure getcc
@class nvarchar(50),
@age int
as
begin
declare @maxscore float
select * from Student where ClassName=@class or Age=@age
select @maxscore=MAX(chinese) from Student where ClassName=@class or Age=@age
return @maxscore
end
//删除存储过程
drop procedure getcc
//监控存储过程
exec sp_monitor