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

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

  1. 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
  2. 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  3. 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
实验:存储过程1 一、实验目的与任务 目的:旨在训练学生能创建带有输入参数的存储过程及带有return语句的存储过程 任务:根据需求,写出满足条件的存储过程。 任务1:在SchoolInfo数据库的基础上,创建ReExam表,脚本如下: --创建ReExam表 Create table ReExam ( StuID char(10) constraint fkStuID1 foreign key references Student(StuID), CourseID int constraint fkCourseID1 foreign key references Course(CourseID) Constraint pkStuCourse1 primary key(StuID,CourseID), Score float constraint chkScore1 check(Score between 0 and 100) ) 注:该表无任何记录!!!。 任务2:写存储过程根据用户输入的不同学号,打印该学号对应的学生姓名、年龄和系名。 答案: create proc prcGetStuInfoByStuID @StuID char(10) AS begin try if exists(select * from Student where StuID=@StuID) begin declare @StuName varchar(20) declare @StuAge int declare @DepName varchar(20) select @StuName=StuName,@StuAge=StuAge,@DepName=DepName from Student JOIN Department on Student.DepID=Department.DepID where StuID=@StuID print @StuName print @StuAge print @DepName end else printInfO does not exist! end try begin catch printerror! end catch 执行: exec prcGetStuInfoByStuID A00001 任务3: 使用存储过程实现由用户输入学生的学号及课程名称,根据输入的信息,显示相应的成绩,如果成绩小于60分,则向ReExam(StuID,CourseID,Score)表中插入一条记录。 答案: create proc prcGetScore @StuID char(10), @CourseName varchar(20) as begin try if exists(select * from SC join Course on SC.CourseID=SC.CourseID where StuID=@StuID and CourseName=@CourseName) begin declare @Grade float set @Grade=0 declare @CourseID int set @CourseID=0 select @Grade=Score,@CourseID=SC.CourseID from SC join Course on SC.CourseID=Course.CourseID where StuID=@StuID and CourseName=@CourseName if @Grade60 insert into ReExam values(@StuID,@CourseID,@Grade) end else printinfo does not exist! end try begin catch printerror! end catch 执行: exec prcGetScore A00001,database 任务4:写一存储过程,根据不同的系名,查

您可能关注的文档

文档评论(0)

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

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

1亿VIP精品文档

相关文档