我想过成功,我想过失败,但是,我从来没有想过放弃。。。

存储过程学习笔记(使用带默认值的参数,使用输出参数)

上一篇 / 下一篇  2012-06-01 11:14:31 / 个人分类:数据库

使用带默认值的参数

源文档 <http://school.itzcn.com/video-vid-2029-spid-48.html>

--创建"员工信息表"的存储过程

create procedure proc_student

@sex varchar(10)

as

select * from 员工信息表 where 性别=@sex

--调用"员工信息表"存储过程

exec proc_student @sex='男'

------新建"部门信息表"

create table 部门信息表

(

部门编号 int not null,

部门名称 nvarchar(20) null

)

---创建"部门信息"表的存储过程

create proc proc_department

@departmentid varchar(10)

as

select * from 部门信息表

----调用"部门信息"表的存储过程

exec proc_department @departmentid='002'

-------

create proc p_employee2

@departmentid varchar(10),

@zhiwei varchar(20)='职员'

as

select A.员工姓名,A.联系电话,B.部门名称

from 员工信息表 A,部门信息表 B

where A.所在部门编号=B.部门编号 and B.部门编号=@departmentid and A.所任职位=@zhiwei

exec p_employee2 @departmentid='001' ,@zhiwei='主管'

使用输出参数

源文档 <http://school.itzcn.com/video-vid-2030-spid-48.html>

----------创建数据库

create database 学生管理系统

on

(

name = 学生管理系统_data,

filename ='E:\SQL学习\学生管理系统_data.mdf',

size=5mb,

maxsize = 20mb,

filegrowth = 20%

)

log on

(

name = 学生管理系统_log,

filename ='E:\SQL学习\学生管理系统_log.ldf',

size = 5mb,

maxsize = 20mb,

filegrowth = 20%

)

--创建表"成绩信息","学生信息"

 

create table 成绩信息

(

学生编号 int not null,

分数 int null

)

create table 学生信息

(

学号 int not null,

姓名 varchar(10) null

)

--创建存数过程,实现输出姓名及平均分数

create proc proc_scoreinfo1

@name nvarchar(10),

@score int output

as

select @score = avg(A.分数)

from 成绩信息 A , 学生信息 B

where A.学生编号=B.学号 and B.姓名=@name

 

--执行存储过程

declare @score1 int

exec proc_scoreinfo1 @name='张三',@score=@score1 output

print @score1


TAG:

 

评分:0

我来说两句

Open Toolbar