SQLServer实验三剖析.docVIP

  1. 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
  2. 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  3. 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
  4. 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
  5. 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们
  6. 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
  7. 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
SQLServer实验三剖析

实验七 (1)创建并运行存储过程student_grade,要求实现如下功能:查询studb数据库中每个学生各门课的成绩,其中包括每个学生的sno、sname、cname和score。 create procedure student_grade as select student.sno,student.sname,course.cname,student_course.score from student join student_course on student.sno=student_course.sno join course on course.cno=student_course.cno 运行结果代码: use Studb go execute student_grade go (2)创建并运行名为proc_exp的存储过程,要求实现如下功能:从student_course表中查询某一学生考试的平均成绩。 create procedure proc_exp @sname varchar(8) as begin select sname,AVG(score) from student join student_course on student.sno=student_course.sno where sname=@sname group by sname end 运行结果代码: use Studb go execute proc_exp @sname=刘招香 go (3)修改存储过程proc_exp,要求实现如下功能:输入学生学号,根据该学生所选课程的平均成绩给出提示信息,即如果平均成绩在60分以上,显示“成绩合格,成绩为XX分”,否则显示“成绩不合格,成绩为XX分”;然后调用存储过程proc_exp,输入学号0705010131,显示成绩是否合格。 alter procedure proc_exp @student_sno varchar (20) as declare @avg varchar(20) set @avg=(select AVG(score) from student_course where sno=@student_sno) if @avg=60 print 成绩合格,成绩为+@avg+分 else print 成绩不合格,成绩为+@avg+分 use Studb go declare @student_sno varchar (20) select @student_sno=0705010131 exec proc_exp @student_sno (4)创建名为proc_add的存储过程,要求实现以下功能:向student_course表中添加学生记录;然后调用存储过程proc_add,向student_course表中添加学生成绩记录。 create procedure proc_add @sno char(10), @cno char(10), @score tinyint as begin set nocount on if not exists (select * from student_course where sno=@sno and cno=@cno and score=@score ) insert into student_course(sno,cno,score) values(@sno,@cno,@score) end 运行结果代码: use studb go exec proc_add 0705010102,0208,80 go 执行前: 执行后: (5)删除存储过程proc_exp和proc_add IF OBJECT_ID(proc_exp) IS NOT NULL DROP PROCEDURE proc_exp IF OBJECT_ID(proc_add) IS NOT NULL DROP PROCEDURE proc_add 实验八 (1)创建触发器student_trg,当删除student表中的数据时,同时删除student_course表中相同的数据;然后通过删除student表中的某个学生记录来验证该触发器。create trigger student_trg on student after delete as begin delete from student_course where sno IN( select sno from deleted ) end 运行结果代码: DELETE FROM studen

文档评论(0)

jiayou10 + 关注
实名认证
文档贡献者

该用户很懒,什么也没介绍

版权声明书
用户编号:8133070117000003

1亿VIP精品文档

相关文档