存储过程

一、简单存储过程

create proc usp_say_hello
as
begin
    print 'HELLO WORLD'
end

exec usp_say_hello


drop proc usp_select_tblStudent

alter proc usp_select_tblStudent
as
begin
    select * from TblStudent where tsgender=''
end

二、带参数的存储过程


--当在存储过程当中需要返回多个值的时候,就可以使用输出参数来返回这些值。
create proc usp_show_students
@gender char(2),
@recordcount int output --输出参数
as
begin
select * from MyStudent where fgender=@gender
--把查询语句查询到的记录的条数赋值给变量@recordcount
set @recordcount=(select count(*) from MyStudent where fgender=@gender)
end


--调用存储过程:
--调用带有输出参数的存储过程的时候,需要定义变量,将变量传递给输出参数,在存储过程中使用的输出参数,其实就是你传递进来的变量
declare @rc int
exec usp_show_students @gender='男',@recordcount=@rc output

print @rc

原文地址:https://www.cnblogs.com/hao-1234-1234/p/8025681.html