日期:2014-05-16  浏览次数:20463 次

存储过程的入门使用的总结

存储过程的基本知识,请先查询百度。

一、创建存储过程:

1、无返回值的

(1)又无参数的

create proc myproc1

as

select * from StudentInfo;

select name from StudentInfo where name like '李%';

(2)有一个参数的

create proc myproc2

@stusex nchar(10)

as

begin

select name from StudentInfo where sex=@stusex;

end

(3)有多个参数的

create proc myproc3

@stusex nchar(10),

@stuage int,

@stuenglish int

as

begin

select name,age,english from StudentInfo where sex=@stusex and

age<@stuage and english>@stuenglish;

end

2、带返回值的

(1)通过output返回的

A、有1个返回值的

create proc myproc4

@stusex nchar(10),

@avgenglish int output

as

begin

select @avgenglish= avg(english) from StudentInfo where sex=@stusex;

end

B、有多个返回值的

create proc myproc5

@stusex nchar(10),

@avgenglish int output,

@maxage int output

as

begin

select @avgenglish= avg(english) from StudentInfo where sex=@stusex