SQL Server数据库应用与实践教程(第2版) 实验文档(带答案) 实验8-存储过程(输出参数).doc

SQL Server数据库应用与实践教程(第2版) 实验文档(带答案) 实验8-存储过程(输出参数).doc

  1. 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
  2. 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  3. 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
实验:存储过程2 一、实验目的与任务 目的:旨在训练学生能创建带有输出参数的存储过程及存储过程调用存储过程。 任务:根据需求,写出满足条件的存储过程。 任务1: 创建存储过程prcGetStuGradeInfo,输入学生的学号,如果输入信息正确,则统计该学生所有科目的最高分和不及格的科目数,并将以上数据使用输出参数返回。 create proc prcGetStuGradeInfo @StuID char(10), @MaxScore int = 0 OUTPUT, @FailCount int = 0 OUTPUT as begin try if exists(select * from SC where StuID=@StuID) begin select @MaxScore = MAX(Score)from SC where StuID=@StuID select @FailCount = COUNT (*) from SC where Score60 and StuID=@StuID end end try begin catch print输入信息错误! end catch declare @MaxScore int declare @FailCount int exec prcGetStuGradeInfoA00001,@MaxScore output,@FailCount output print @MaxScore print @FailCount 任务2: 针对存储过程prcGetStuGradeInfo的返回值写一存储过程,如果不及格数大于等于3门,则提示用户‘亲,您挂了,重头再来吧!’;否则显示学生已获学分。假设Course表(CourseID,CourseName,Credit)。 alter proc prcPrintCredit @StuID char(10) as begin try declare @MaxScore int declare @FailCount int exec prcGetStuGradeInfoA00001,@MaxScore output,@FailCount output if(@FailCount=3) print亲,您挂了,重头再来吧! else begin declare @Credit int select @Credit = SUM(Credit) from SC join Course on SC.CourseID = Course.CourseID where StuID = @StuID and Score =60 print @Credit end end try begin catch print出错! end catch exec prcPrintCredit A00001 任务3:写一个存储过程,查找某个学生是否选修了某门课程,如果选修了则返回1,否则返回0,错误返回-1. create proc prcGetCourseName @StuID char(10), @CourseName char(20) as begin try if exists(select * from SC join Course on SC.CourseID = Course.CourseID where StuID = @StuID and CourseName = @CourseName) begin return 1 end else return 0 end try begin catch return -1 end catch 再写一个存储过程调用上一存储过程,当返回值为1,显示选修成绩,为0时提示用户信息有误,-1时提示出错了。 alter proc prcPrintScore @StuID char(10), @CourseName char(20) as begin try declare @Score int declare @ReturnValue int exec @ReturnValue = prcGetCourseName @StuID,@CourseName if(@ReturnValue = 1) begin select @Score = Score from SC join Course on SC.CourseID = Course.CourseID where StuID = @StuID and CourseName = @Cours

您可能关注的文档

文档评论(0)

xiaobao + 关注
实名认证
内容提供者

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

1亿VIP精品文档

相关文档