作业——精选推荐

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

作业
第⼋章
1、创建⼀个名为StuInfo的存储过程,要求完成以下功能:在student表中查询08级学⽣的学号、姓名、性别、出⽣⽇期和电话5个字段的内容
create procedure StuInfO
as
select studentno,sname,sex,birthday,phone
from student
WHERE SUBSTRING(studentno,1,2)='09'
GO
2、创建⼀个名为ScoreInfo的存储过程,完成的功能是在表student、在表course和表score 中查询以下字段:学号、姓名、性别、课程名称、期末分数。

create procedure ScoreInfO
as
select student.studentno,sname,sex,cname,kscj
from student inner join score on student.studentno=score.studentno inner join course on score.courseno=course.courseno GO
2.1
create procedure student_score2
@student_name nchar(8)
as
select student.studentno,sname,sex,cname,kscj
from student inner join score on student.studentno=score.studentno inner join course on score.courseno=course.courseno where sname=@student_name
GO
exec student_score2@student_name='刘平'
go
1.2
create procedure StudentInfO
@stu_nj char(2)
as
select studentno,sname,sex,birthday,phone
from student
WHERE SUBSTRING(studentno,5,2)=@stu_nj
GO
exec StudentInfO@stu_nj='10'
go
3、创建⼀个带有参数的存储过程student1,该存储过程根据输⼊的学号,在student表中计算此学⽣的年龄。

create procedure student1
@stu_studentno char(10),
@age int output
as
select@age=YEAR(GETDATE())-YEAR(birthday)
from student
WHERE studentno=@stu_studentno
GO
declare@ave int
exec student1@stu_studentno='020*******',@age=@ave output
select@ave as平均分
go
4、创建⼀个`insert触发器tr_stu_insert,当在student表中插⼊⼀条新记录时,触发该触发器,并给出“你插⼊了⼀条新记录!”的提⽰信息。

create trigger TR_Stu_Insert
on student
after insert
as
raiserror('你已经插⼊了⼀条新记录',16,2)
go
insert into student(studentno,sname,sex,birthday)
values('0000000000','fuck','男','1987-12-25')
go
5、创建⼀个after触发器,要求以实现以下功能:在score表上创建⼀个插⼊、更新类型的触发器TR_sCOREcHECK,当在score字段中插⼊或修改考试分数后,触发该触发器,检查分数是否在0-100之间。

6、创建⼀个instead of 触发器,要求实现以下功能:在course表上创建⼀个删除类型的触发器TR_NotAllowDELETE,当在course表中删除记录时,触发该触发器,显⽰不允许删除表中数据的提⽰信息。

相关文档
最新文档