收藏 分销(赏)

数据库系统月考二试卷及答案.doc

上传人:快乐****生活 文档编号:4117831 上传时间:2024-07-30 格式:DOC 页数:3 大小:32.54KB 下载积分:5 金币
下载 相关 举报
数据库系统月考二试卷及答案.doc_第1页
第1页 / 共3页
数据库系统月考二试卷及答案.doc_第2页
第2页 / 共3页


点击查看更多>>
资源描述
第 二次月考 设有一个学生选课数据库,包括如下三个关系模式: Student(Sno,Sname,Ssex,Sage,Sdept); Course(Cno,Cname,Cpno,Credit); SC(Sno,Cno,Grade)。 Student表示学生,它的各属性依次为学号、姓名、性别、年龄、系别; 设置Sno为主码, Sname值非空,Ssex默认值为‘男’。 Course表示课程,它的各属性依次为课程号、课程名、先行课、学分; 设置Cno为主码,Cname值唯一,Cpno值可以为空。 SC表示学生选课信息,它的各属性依次为学号、课程号、学生所学课程的成绩。 设置Sno、Cno为主码,Grade可以为空、设置check约束取值范围为0—100,设置外键约束Sno参考Student表的属性Sno、Cno参考Course表的属性Cno。 其中,Sage、Credit、Grade三个属性为int型,其余各属性为char型. 一、用SQL语句创建Student表、Course表、SC表。(30分) (1) 10分 create table student (sno char(9) primary key,/*列级完整性约束,设置sno为主码*/ sname char(20) not null,/*列级完整性约束,要求sname值非空*/ ssex char(2) default‘男’, /*默认值约束, ssex默认值为‘男'*/ sage int, sdept char(20)); (2) 10分 create table course (cno char(4) primary key,/*列级完整性约束,设置cno为主码*/ cname char(20) unique,/*列级完整性约束,要求cname值唯一*/ cpno char(2) null, /*cpno值可以为空*/ credit int ); (3) 10分 create table sc (sno char(9), cno char(4), grade int check((grade IS NULL)OR(grade between 0 AND 100)), /*check约束限制grade取值范围*/ Primary key(sno,cno), /*表级完整性约束,主键约束*/ Foreign key(sno) references student(sno), /*外键约束*/ Foreign key(cno) references course(cno) /*外键约束*/); 二、请用SQL语句完成如下操作:(70分) (1)将学生记录(学号:95010,姓名:陈东,性别:男,年龄:18,所在系:IS)插入到student表中。(5分) insert into student values (’95010’, ’陈东’, ’男' , 18, ’IS'); (2)查询student表中学生属于哪些系。(5分) select distinct sdept from student; (3)查询年龄不在18到20之间的学生姓名。(5分) select sname, sdept from student where sage not between 18 and 20 (4)从学生表中统计姓‘刘’的学生的学号和姓名。(5分) select sno,sname from student where sname like ‘刘%’; (5)查询各系学生的平均年龄,将查询结果按照年龄的平均值降序输出.(10分) select sdept,avg(sage) from student group by sdept order by avg(sage) DESC; (6)查询李勇的数据库课程的成绩.(10分) select student.sno , sname , cname ,grade from student, course, sc where student。sno=sc。sno and course。cno=o and sname =’李勇’ and cname='数据库'; (7) 查询学生人数大于5的系。(10分) select sdept, count(*) from student group by sdept having count(*)>5; (8)建立MA系学生的视图。(10分) create view MA_student AS select * from student where sdept=’MA’; (9) 把对表course的查询权限授予用户U5,并允许他再将此权限授予其他用户. grant select on table course to U5 with grant option; 3 / 3
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传

当前位置:首页 > 包罗万象 > 大杂烩

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2025 宁波自信网络信息技术有限公司  版权所有

客服电话:4009-655-100  投诉/维权电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服