erwherecourset
oteachert
oa
ddepart计算机系a
dtsex男
调用此存储过程
Execstude
t_11
f2创建一个带输入参数的存储过程。
调用此存储过程时给出一个学生名显示出此学生的学号姓名所学课程号课程名称和对应的成绩
createprocstude
t_
ame
s
amevarchar10
as
selectstude
ts
os
amescorec
odegreec
amefromstude
tscorecourse
wherestude
ts
oscores
oa
dscorec
ocoursec
oa
ds
ames
ame
调用此存储过程此例是输出姓名为历史的学生的信息
execstude
t_
ame历史
3创建一个存储过程传递一个学生姓名。
先判断此学生是否有邮箱如果有则显示此学生的姓名邮箱地址学号班级如果没有的话输出此句话thesemailisempty
createprocstude
t_email
s
amevarchar10
as
begi
ifselectsemailfromstude
twheres
ames
ameis
ull
begi
pri
tthesemailisempty
e
d
else
selects
amesemails
oclassfromstude
twheres
ames
ame
e
d
f调用此存储过程
execstude
t_emailsuper
当给出姓名的那个学生没有邮箱地址时则会显示如下内容。
execstude
t_emaildfdf
47触发器
1创建一个触发器。
来检查学生的邮箱地址是否相同如果相同输出i
serti
gfail并且回滚事务如果不相同则插入成功。
createtriggerstude
ti
sert
o
stude
t
afteri
sert
as
ifselectsemailfromi
sertedwheresemaili
selectsemailfromstude
tis
ot
ull
begi
pri
ti
serti
gfail
rollbacktra
sactio
e
d
else
pri
ti
seri
gsucceed
向学生信息表中插入一条记录检验是否成功插入
i
serti
tostude
tvalues114le
gbi
g女1985121211一般
2在成绩表中建立一个触发器
当向表中添加记录时此学生的成绩都乘以12
createtriggerscoreupdateo
score
afteri
sert
as
updatescoresetdegreedegree12fromscorewheres
oi
selects
ofromi
serted
向表中插入一条记录检验触发器是否有用。
i
serti
toscorevalues1080156
48自定义函数
f1创建一个用户自定义函数输出与指定的学生同班的学生个数
createfu
ctio
stude
tcou
ts
ochar5retur
si
t
begi
declarecou
teri
t
selectcou
tercou
tfromstude
twhereclassselectclassfromstude
twheres
os
o
retur
cou
ter
e
d
调用此自定义函数本例是查找与学号102同班的学生个数
declareai
t
setadbostude
tcou
t102
pri
tco
vertchar3a
2创建一个用户自定义函数用于输出同一个班级中的学生信息
createfu
ctio
stude
tclass
classchar5
retur
stable
retur
selectfromstude
twhereclassclass
调用自定义函数本例是输出12班的学生信息
selectfromstude
tclass12
下图显示了学生课程和成绩三个关系的物理设计其中课程号与学号号分别为关系的主码。
五、数据库的实施与维护
51数据库的实施
此阶段主r