JBQK.lx=QQLX.lx and not in(select lx,mc from JBQK) 9.使用SQL语句将“旷工”人员的缺勤天数增加一天。 update JBQK set ts=ts+1 where lx='旷工'
10.使用SQL语句创建一个名为zgqq(职工缺勤)的视图,要求能够使用该视图查询缺勤2天以上的职工的职工号、姓名、缺勤天数和缺勤名称。 create view zgqq as
select zgh,xm,ts,mc from JBQK,QQLX
where JBQK.lx=QQLX.lx and ts>2
(二)某大学的运动会比赛项目管理数据库包括如下三张表: Student(xh,xm,xb,nl,szx)
各属性分别表示学生的(学号、姓名、性别、年龄、所在系)。 Sports(xmh,xmm,dw)
各属性分别表示(运动项目的编号、名称、项目的计分单位)。 SS(xh,xmh,cj)
各属性分别表示(学号、运动项目的编号、成绩)。 根据上述情况,完成如下操作:
1. 使用SQL语言,创建student表,并定义xh为主键。 create table student(
xh char(4) primary key, xm char(6), xb char(2), nl int, szx char(8))
2. 在Student表xh属性列上建立名称为xh的聚簇索引。 create cluster index Student_xh on student(xh);
3. 使用SQL语言 从表Student中删除学生“张三”的记录。 delete from student where xm=' 张三'
4. 使用SQL语言为SS表添加一条记录:学号为“xh001”的学生参与了编号为“xm001”的运动项目,但还没成绩。 insert into ss(xh,xmh) values('xh001','xm001') 5. 使用SQL语言,将Student表学号为“xh001”的学生的姓名改为“李明”。
update student set xm='李明' where xh='xh001' 6. 查询“计算机”系的学生参加了哪些运动项目,只把运动项目名称列出,去除重复记录。 select distinct xmm from student,sports,ss
where student.xh=ss.xh and sports.xmh=ss.xmh and szx='计算机'
7. 查询各个系的学生的“跳高”项目比赛的平均成绩 (不要求输出比赛项目的计分单位) 。 select avg(cj) from student,sports,ss
where student.xh=ss.xh and sports.xmh=ss.xmh and xmm='跳高' group by szx;
8. 统计各个系的总成绩情况,并根据总成绩按降序排序。 select count(cj) 总成绩 from student,ss where student.xh=ss.xh group by szx order by 总成绩
9. 建立“计算机”系所有男学生的信息视图JSJ_M_Student。 create view JSJ_M_Student as
select * from Student
where szx='计算机' and xb='男' 10.
回收用户“李明”对Sports表的查询权限。
revoke select on table Sports from 李明
(三)有一个“学生选课”数据库,数据库中包括三个表,其关系模式分别为:
Student(xh,xm,xb,nl,szx) Course(kch,kcm,xxk,xf) SG(xh,kch,cj)
其中:Student是学生表,xh表示学号、xm表示姓名、sb表示性别、nl表示年龄、szx表示所在系。xh为主码。
Course是课程表,kch表示课程号、kcm表示课程名、xxk表示先修课号、xf表示学分。kch为主码。
SG是选课表,xh表示学号,参照学生表的学号xh、kch表示课程号,参照课程表的课程号kch、cj表示成绩。(xh,kch)为主码。 请用SQL语言实现下列功能:
1.建立选课表SG,要求实现主键约束和外键约束,且成绩不能为空。 create table SG( xh char(5), kch char(5), cj int
primary key(xh,kch),
foreign key(xh) references Student(xh), foreign key(kch) references Course(kch)) 2.查询选修课程的成绩小于60分的人数。 select count(*) from SG where cj<60
3.查询选修了C3号课程的学生的学号及其成绩,查询结果按分数的降序排列。要求查询结果的标题显示为汉字。
select xh 学号,cj 成绩 from SG where kch='C3' order by cj
4.查询选修了“数据库应用”课程且成绩在90分以上的学生的姓名和所在系。
select xm,szx from Student s,Course c,SG g
where s.xh=g.xh and c.kch=g.kch and kcm='数据库应用' and cj>90 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