工作这么久了,但不会存储过程,决定抽时间学习下.
例子一 新建存储过程
CREATE PROCEDURE hello
as
select top 2 * from student;
新建立一个名为hello的存储过程
调用: hello
例子二 修改存储过程
修改存储过程,设置需要传入参数xid
ALTER PROCEDURE hello @xid int // 声明要传入int类型的参数,形参名为xid
as
select top 2 * from student where id = @xid
调用: hello 123
hello @xid = 123
例三 带输出参数的存储过程
ALTER PROCEDURE hello
@idx int,
@count int output
AS
select @count=count(*) from TableA where id = @idx
调用:
declare @countxx int
exec hello 61082,@countxx output
print @countxx
例四 分页存储过程