数据库原理与应用期末考试复习题 联系客服

发布时间 : 星期四 文章数据库原理与应用期末考试复习题更新完毕开始阅读

5.向Student表中插入一条记录,学号为“05020”,姓名为“丁莉”,性别为“女”,年龄为“17”,所在系为“计算机系”。 insert into Student

values('05020','丁莉',‘女’,‘17’,‘计算机’) 6.将计算机系全体学生的成绩置零。 update SG set cj=0

where '计算机'=(select szx from Student where Student.xh=SG.xh ) 7.创建一个“学生成绩”视图,包括选修了课程的学生的学号、姓名、选修课程的课程号、课程名以及成绩。 create view 学生成绩 as

select s.xh,xm,g.kch,kcm ,cj from Student s,Course c,SG g where s.xh=g.xh and c.kch=g.kch

8.为Student表建立一个按学号升序排列的唯一索引Stusno_IDX。 create unique index Stusno_IDX on Student(xh) order by xh

9.求各课程的选修人数及平均成绩。

select count(xh),avg(cj) from SG group by kch

10.查询选修了课程编号为’14001’和’14002’课程的学生的学号和姓名。 select s.xh,xm from Student s,SG g

from Student s,SG g

where kch='14001' or kch='14002'

(四)设有如下所示的三个关系模式:商店Shop(bh,mc,cs),商品Product(sph,spm,jg),商店所售商品SP(bh,sph,sl),其中带下划线的字段为主键。各属性含义如下:bh (商店编号)、mc (商店名)、cs (所在城市)、sph (商品编号)、spm(商品名称)、jg (价格)、sl (商品数量)。

ShopSP bh mc Cs 长沙 北京 北京 长沙 上海 jg 21 5 300 76 bh 101 101 101 101 204 256 256 345 345 345 620 sph sl 1 2 3 4 3 1 2 1 2 4 4 105 42 25 104 61 241 91 141 18 74 125 101 百货商店 204 长安商场 256 西单商场 345 铁道商店 620 太平洋百货 Product sph spm 1 2 3 4 钢笔 羽毛球 复读机 书包 试用SQL语言完成下列操作: (1)用Create语句创建商店表Shop,要求创建主键,商店名不允许为空,各属性的数据类型根据表中所给数据选定。

creat table Shop( bh char(4) primary key, mc char(10) not null, cs char(4))

(2)检索所有商店的商店名和所在城市。 select mc,cs from Shop

(3)检索价格低于50元的所有商品的商品名和价格。 select spm,jg from Product where jg<50

(4)检索位于“北京”的商店的商店编号,商店名,结果按照商店编号降序排列。

select bh,mc from Shop where cs='北京' order by bh;

(5)检索供应“书包”的商店名称。 select mc from Shop s,Product p,SP

where s.bh=SP.bh and p.sph=SP.sph and spm='书包'; (6)检索所有商场中各种商品的平均数量。

select avg(sl) from SP group by sph;

(7)将商品“复读机”的价格修改为350。 update Product set jg=350 where spm='复读机';

(8)将“百货商店”的商店名修改为“百货商场”。 update Shop set mc='百货商场' where mc='百货商店'; (9)创建视图:“铁道商店”所售商品的商品编号,商品名和数量。 create view 铁道商店 as

select sph,spm,sl from Product p,SP where p.sph=SP.sph ;

(10)将查询和更新SP表的权限赋给用户U1。 grant select,update on table SP to U1;

(五)已知研究生管理数据库YJSGL包含graduate(研究生信息)数据表和teacher(导师信息)数据表,表结构如表1和表2所示:

表 1 graduate(研究生信息表结构) 字段名 bh xm xb mz ly cj dsbh 字段名 dsbh dsxm zc dh 字段类型 char char char char char int char 字段类型 char char char char 字段宽度 4 8 2 20 20 说明 研究生编号(主码) 姓名 性别 民族 来源地区 入学成绩 导师编号(外码) 说明 导师编号(主码) 姓名 职称 联系电话 4 字段宽度 4 8 10 11 表 2teacher(导师信息表结构) 请用SQL语句完成以下操作:

1. 查询每个研究生的编号、姓名、性别、民族、入学成绩、来源地区和所选导师编号。 select * from graduate

2. 查询学号为1001的学生的姓名和入学成绩。 select xm,cj from graduate where bh='1001'

3.查询所有姓“王”的学生的编号和来源地区。 select bh,ly from graduate where mc like '王%';

4.查询所有入学成绩在350和400分之间的学生的编号、姓名和所选导师的姓名及其职称。

select bh,xm,dsxm,zc from graduate g,teacher t where g.dsbh=t.dsbh and cj between 350 and 400; 5.查询选了“张一伟”为导师的研究生的编号和姓名。 select bh,xm from graduate g,teacher t where g.dsxm=t.dsxm and dsxm='张一伟';

6.查询入学成绩低于平均入学成绩的研究生的编号、姓名、民族。 select bh,xm,mz from graduate where cj<(select avg(cj) from graduate); 7.查询不同来源地区的研究生人数。 select count(bh) from graduate group by ly;

8.查询没有选导师的研究生的编号、姓名、性别和入学成绩。 select bh,xm,xb,cj from graduate g where dsbh is not null

9.将少数民族的研究生的入学成绩加10分。