sql存储过程简单例题_sql存储过程实例详解

sql存储过程简单例题_sql存储过程实例详解1、创建存储过程P1,查询每个学生的修课门数,要求列出学生学号、姓名及修课门数。createprocP1asselectStudent.StudentID,StudentName,count(CourseID)选修门数fromStudentjoinGradeonGrade.StudentID=Student.StudentIDgroupbyStudent.StudentID,StudentNamego2、创建存储过程P2,查询学生的学号、姓名、课程名、成绩

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

1、创建存储过程P1,查询每个学生的修课门数,要求列出学生学号、姓名及修课门数。

create proc P1

as

select Student.StudentID,StudentName,count(CourseID)选修门数 from Student join Grade

on Grade.StudentID=Student.StudentID

group by Student.StudentID,StudentName

go

2、创建存储过程P2,查询学生的学号、姓名、课程名、成绩,将学生所在系作为输入参数

create proc P2

@departmentname varchar(20)

as

select Student.StudentID,StudentName,CourseName,Grade from Student join Grade

on Grade.StudentID=Student.StudentID join Course

on Course.CourseID=Grade.CourseID join Class

on Class.ClassID=Student.ClassID join Department

on Department.DepartmentID=Class.DepartmentID

where DepartmentName=@departmentname

go

3、创建存储过程P3,查询指定系的男生人数,其中系为输入参数,人数为输出参数。

create proc P3

@departmentname varchar(20),

@num int output

as

select @num=count(StudentID) from Student join Class

on Class.ClassID=Student.ClassID join Department

on Department.DepartmentID=Class.DepartmentID

where DepartmentName=@departmentname and Sex='男'

go

4、创建存储过程P4,删除指定学生的修课记录,其中学号为输入参数。

create proc P4

@sid char(12)

as

 delete  from  Grade where  StudentID=@sid

go

5、创建存储过程P5, 通过输入教师的教师号返回教师性别

create proccP5

@tid char(8),

@sex char(2) output

as

select @sex=Sex from Teacher where TeacherID=@tid

6、创建存储过程P6,通过输入的班级名称能够返回该班级的女生人数。

create proc P6

@cname varchar(20),

@gnum int output

as

select @gnum=count(StudentID)from Student join Class

on Class.ClassID=Student.ClassID

where ClassName=@cname and Sex='女'

go

7、创建存储过程P7,通过输入的班级名称能够返回该班级的平均成绩。

create proc P7

@cname varchar(20),

@avg int output

as

select @avg=avg(Grade) from Grade join Student

on Student.StudentID=Grade.StudentID join Class

on Class.ClassID=Student.ClassID

where ClassName=@cname

go

8、创建存储过程P8,通过输入的教师姓名能够返回该老师的职称

create proc P8

@tname char(12),

@profession char(8) output

as

select @profession=Profession from Teacher where Teachername=@tname

9、创建存储过程P9,通过输入学生的学号与课程的课程号查询成绩

create proc P9

@sid char(12),

@cid char(8),

@grade numeric(5,2) output

as

select @grade=Grade from Grade where CourseID=@cid and StudentID=@sid

go
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/188663.html原文链接:https://javaforall.net

赞 (0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 自己定义对象的监听方式

    自己定义对象的监听方式

    2021年11月16日
  • 【Mongodb】sharding 集群Add/Remove 节点

    【Mongodb】sharding 集群Add/Remove 节点

    2021年9月14日
  • TypeError: ‘Collection‘ object is not callable. If you meant to call the ‘insert‘ method on a ‘Datab

    TypeError: ‘Collection‘ object is not callable. If you meant to call the ‘insert‘ method on a ‘DatabfrompymongoimportMongoClient报错问题描述解决方法问题描述使用pymongo连接本地的MongoDB,跟个老师的视频,出现报错,后查询资料改正frompymongoimportMongoClient#创建数据库连接对象client=MongoClient()#选择一个数据库db=client[‘python’]#身份认证#db.authenticate(‘python’,’python’)#选择一个集合col=c

    2022年7月16日
  • osip状态机分析「建议收藏」

    osip状态机分析「建议收藏」OSIP的核心是系统状态机,在不同情况下,系统处于不同的状态,在某一状态下当系统发生某一个动作后(如接受或者发送了消息),状态机做相应的跳转。的状态机在不同的状态下,对某一动作的响应也是不一样的。由于SIP的复杂性,为了降低代码实现难度,也为了能够保证代码的模块化,Osip把整个SIP的实现分成了四个状态机,分别是:      (1)ICT(带invit事件的out处理)

    2022年6月15日
  • 最小二乘法详解_通俗是啥意思

    最小二乘法详解_通俗是啥意思本文转自https://blog.csdn.net/bitcarmanlee/article/details/51589143,谢谢原作者辛苦整理。若侵权,告知即删。最小二乘是每个上过大学的同学都接触过的概念与知识点(当然可能纯文科的同学没接触过,但是一般纯文科的同学也不会看这篇文章好像)。最小二乘理论其实很简单,用途也很广泛。但是每次说到最小二乘,总感觉差了点什么似的,好像对于最小二乘的前世…

    2022年8月30日
  • Java的三种取整方法「建议收藏」

    方法一:向上取整Math.ceil();举例:Math.ceil(11.4)=12;Math.ceil(-11.6)=-11;方法二:向下取整Math.floor();举例:Math.floor(11.7)=11;Math.floor(-11.2)=-12;方法三:四舍五入Math.round();顾名思义,四舍五入后取整,其算法为Math.round(x+0.5),即原来的数字加上0.5后再想下

    2022年4月10日

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号