华工数据库实验题(共9页).doc
《华工数据库实验题(共9页).doc》由会员分享,可在线阅读,更多相关《华工数据库实验题(共9页).doc(9页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、精选优质文档-倾情为你奉上1,创建Student数据库,包括Students,Courses,SC表,表结构如下:Students(SNO,SNAME,SEX,BDATE,HEIGHT,DEPARTMENT)Courses(CNO,CNAME,LHOUR,CREDIT,SEMESTER)SC(SNO,CNO,GRADE)(注:下划线表示主键,斜体表示外键),并插入一定数据。答:create table Students(SNO varchar(100) primary key ,SNAME varchar(100) null,SEX varchar(100) null,BDATE dateti
2、me null,HEIGHT decimal null,DEPARTMENT varchar(100) null)gocreate table Courses(CNO varchar(100) primary key ,CNAME varchar(100) null,LHOUR int null,CREDIT int null,SEMESTER varchar(100) null)goCREATE TABLE dbo.SC(SNO varchar(100) NOT NULL,CNO varchar(100) NOT NULL,GRADE int NULL, CONSTRAINT PK_SC P
3、RIMARY KEY CLUSTERED (SNO ASC,CNO ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON PRIMARY) ON PRIMARYGOALTER TABLE dbo.SC WITH CHECK ADD CONSTRAINT FK_SC_Courses FOREIGN KEY(CNO)REFERENCES dbo.Courses (CNO)GOALTER TABLE d
4、bo.SC CHECK CONSTRAINT FK_SC_CoursesGOALTER TABLE dbo.SC WITH CHECK ADD CONSTRAINT FK_SC_Students FOREIGN KEY(SNO)REFERENCES dbo.Students (SNO)GOALTER TABLE dbo.SC CHECK CONSTRAINT FK_SC_Students2完成如下的查询要求及更新的要求。(1)查询身高大于1.80m的男生的学号和姓名;答:select SNO,SNAME from Students where HEIGHT1.8(2)查询计算机系秋季所开课程的
5、课程号和学分数;答:select CNO,CREDIT from Courses where SEMESTER=秋季(3)查询选修计算机系秋季所开课程的男生的姓名、课程号、学分数、成绩;答:select s.SNAME,SC.CNO,c.CREDIT,SC.GRADE from students sinner join SC on sc.SNO=s.SNOinner join Courses c on sc.CNO=c.CNOwhere s.DEPARTMENT=计算机系 and s.SEX=男 and c.SEMESTER=秋季(4)查询至少选修一门电机系课程的女生的姓名(假设电机系课程的课
6、程号以EE开头);答:select distinct s.sname from Students s,sc where s.sno=sc.sno and s.sex=女 and o like EE%(5)查询每位学生已选修课程的门数和总平均成绩;答:select count(c.CNO) as 课程门数,avg(SC.GRADE) as 总平均成绩from students sinner join SC on sc.SNO=s.SNOinner join Courses c on sc.CNO=c.CNOgroup by s.SNO(6)查询每门课程选课的学生人数,最高成绩,最低成绩和平均成绩
7、;答:select cname,count(cno),max(grade),min(grade),avg(grade)from students natural join sc natural join coursesgroup by chane;(7)查询所有课程的成绩都在80分以上的学生的姓名、学号、且按学号升序排列;答:select sname,sno from students natural join (select sno.min(grade)as mini from sc group by sno)where mini80 order by(sno);(8)查询缺成绩的学生的姓名
8、,缺成绩的课程号及其学分数;答:select sname,o,creditfrom students,courses,scwhere students.sno=sc.sno and o=o and grade is null;(9)查询有一门以上(含一门)三个学分以上课程的成绩低于70分的学生的姓名;答:select sname from students,courses,scwhere students.sno=sc.sno and o=sc.cho and credit=3 and grade70;(10)查询1984年1986年出生的学生的姓名,总平均成绩及已修学分数。答:select
9、smane,avg(grade),sun(credit)from students natural join sc natural join courseswhere bdate between 1984-00-00 and 1987-00-00group by sname;(11) 在STUDENT和SC关系中,删去SNO以01开关的所有记录。答:delete sc where SNO like %01%delete Students where SNO like %01%(12)在关系中增加以下记录:答:insert into students values(,何平,女,1987-03-0
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 华工 数据库 实验
限制150内