版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
第6次作业——存储过程一、环境运行SQLServer,已创建名为student数据库、“学生信息”表、“课程”表、“学生成绩”表。(参考实训二)二、实训内容(1)使用createprocedure命令建立名为StudentCourseScore存储过程,该存储过程用于查询“学生选课名称、学分及分数”视图中的数据。写出程序代码。 usestudentgoifexists(selectnamefromsysobjectswherename='pr_StudentCourseScore'andtype='P')dropprocedurepr_StudentCourseScoregocreateprocedurepr_StudentCourseScoreasselecta.课程名称,a.学分,b.分数from学生成绩_蒲强林b,学生课程_蒲强林awherea.课程号=b.课程号goexecpr_StudentCourseScorego运行结果截图:(2)使用带参数的存储过程StudentAge,根据制定的“年龄”,找出与给定“年龄”相等的学生的“学号”和“姓名”。写出程序代码。 usestudentgoifexists(selectnamefromsysobjectswherename='pr_StudentAge'andtype='P')dropprocedurepr_StudentAgegocreateprocedurepr_StudentAge@ageintasselect学号,姓名from学生信息_蒲强林where年龄=@agegoexecpr_StudentAge19go运行结果截图:(3)在上题中设置@count参数,作为输出参数,返回和给定“年龄”相同的学生的总人数。写出程序代码。 usestudentgoifexists(selectnamefromsysobjectswherename='pr_StudentAge'andtype='P')dropprocedurepr_StudentAgegocreateprocedurepr_StudentAge@ageint,@countintoutputasselect@count=count(*)from学生信息_蒲强林where年龄=@agegodeclare@Scountintexecpr_StudentAge20,@Scountoutputprint'年龄为19的学生总数为:'+cast(@Scountaschar(4))go运行结果截图:(4)使用存储过程实现向“学生信息”表插入一条记录的操作。 usestudentgoifexists(selectnamefromsysobjectswherename='pr_InsStuInfo'andtype='P')dropprocedurepr_InsStuInfogocreateprocedurepr_InsStuInfo@学号char(7),@姓名char(20),@性别char(2),@年龄int,@所在系char(15),@flagintoutputasbegin set@flag=1 insertinto学生信息_蒲强林values(@学号,@姓名,@性别,@年龄,@所在系) if@@ERROR<>0 set@flag=0endreturngodeclare@flagintset@flag=0execpr_InsStuInfo'008','张三','男',21,'计算机',@flagoutputif@flag=1print'学生信息添加成功!'elseprint'学生信息添加失败!'go运行结果截图:(5)在“学生信息”表中,修改和所给的“学号”相同的记录,用存储过程实现。 usestudentgoifexists(selectnamefromsysobjects wherename='pr_UpdStuInfo'andtype='P')dropprocedurepr_UpdStuInfogocreateprocedurepr_UpdStuInfo@学号char(7),@姓名char(20),@性别char(2),@年龄int,@所在系char(15),@flagintoutputasset@flag=1ifexists(select*from学生信息_蒲强林where学号=@学号)update学生信息_蒲强林set姓名=@姓名,性别=@性别,年龄=@年龄,所在系=@所在系where学号=@学号elseset@flag=0returngodeclare@flagintset@flag=0execpr_UpdStuInfo'008','张三','男',21,'计算机',@flagoutputif@flag=1print'学生信息修改成功!'elseprint'学生信息修改失败!’godeclare@flagintset@flag=0execpr_UpdStuInfo'009','李四','男',21,'计算机',@flagoutputif@flag=1print'学生信息修改成功!'elseprint'学生信息修改失败!’go运行结果截图:(6)在“学生信息”表中,删除和所给的“学号”相同的记录,用存储过程实现。usestudentgoifexists(selectnamefromsysobjects wherename='pr_DelStuInfo'andtype='P')dropprocedurepr_DelStuInfogocreateprocedurepr_DelStuInfo@学号char(7),@flagintoutputasbeginset@flag=1ifexists(select*from学生信息_蒲强林where学号=@学号)delete学生信息_蒲强林where学号=@学号elseset@flag=0endreturngodeclare@flagint,@学号char(7)set@学号='008'set@flag=0execpr_DelStuInfo@学号,@flagoutputif@flag=1print'该学生信息删除成功!'elseprint'该学生不存在,无法删除!'go运行结果截图:(7)使用存储过程实现向“学生成绩”表插入一条记录的操作。usestudentgoifexists(selectnamefromsysobjects wherename='pr_InsGrade'andtype='P')dropprocedurepr_InsGradegocreateprocedurepr_InsGrade@学号char(7),@课程号char(7),@分数int,@flagintoutputasbeginset@flag=1ifexists(select*from学生课程_蒲强林,学生信息_蒲强林where学号=@学号and课程号=@课程号)insert学生成绩_蒲强林values(@学号,@课程号,@分数)elseset@flag=0endreturn@flaggodeclare@Snochar(7),@Cnochar(7),@分数int,@flagintset@Sno='9056299'set@Cno='0000005'set@分数=80execpr_InsGrade@Sno,@Cno,@分数,@flagoutputif@flag=1print'该学生成绩添加成功!'elseprint'该记录中学号或课程号不存在,无法添加!'go(8)在“学生成绩”表中,删除和所给的“学号”、“课程号”都相同的记录,用存储过程实现。usestudentgoifexists(selectnamefromsysobjects wherename='pr_DelGrade'andtype='P')dropprocedurepr_DelGradegocreateprocedurepr_DelGrade@学号char(7),@课程号char(7),@flagintoutputasbeginset@flag=1ifexists(select*from学生成绩_蒲强林where学号=@学号and课程号=@课程号)delete学生成绩_蒲强林where学号=@学号and课程号=@课程号elseset@flag=0endreturn@flaggodeclare@Snochar(7),@Cnochar(7)
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2024年特种功能焊接材料项目投资申请报告代可行性研究报告
- 《机器学习-Python实践》试卷3
- 临床医学课件 急性肾小球肾炎
- 2024年离婚第三次财产分割协议书范文
- 《计算机网络安全防护技术(第二版)》 课件 第4章 任务4.3.2 配置瘦客户端SSL VPN
- 职测判断推理:类比推理之功用关系
- 鑫钢机械厂玉米脱粒机生产项目环境现状评估报告
- 期中模拟检测1-4单元2024-2025学年度第一学期冀教版三年级数学
- 员工福利计划与激励机制
- 2024中国实战化白帽人才能力白皮书
- 钢结构竣工资料范本模板(共155页)
- 气旋与反气旋教学课件
- 人教版六年级数学上册《第三单元 分数除法》拓展提升练习题爬坡题及答案解析
- 职业健康体检质量管理手册(共58页)
- 苏教版六年级上册数学《第三单元 分数除法 第5课时 分数除法的实际问题》课件
- Multisim电子技术基础仿真实验二菜单栏学习教案
- 浅谈中学生学习焦虑的原因及对策
- 《大队长竞选》PPT课件.ppt
- 佳能IPF系列绘图仪错误代码解释
- 拼音田字格A4打印版
- 《申(换、补)领居民身份证登记表》(样表)
评论
0/150
提交评论