1. insert into ustudent
values('112007015', '陈阳', '男', '1987-02-11 00:00:00', '01', '661123')
2. insert into udept(did, dname, daddr, dtele)
values('MA', '数学系', 'NB211', '88220780')
3.
--为洪玉飞老师(教师编号:03012)安排软件工程1班(班级编号:04)的数据库课程(课程编号:1),上课教师为nb201。
insert into ujobtable
values('1', 'nb201', '03012', 4, '12', '04', '2009-2010-1')
4.
--计算机科学与技术3班所有学生都选修了2009-2010-1的操作系统(课程编号为4),请记录相关信息。
insert into usc(sid, cid, term)
select sid, '4', '2009-2010-1' from ustudent where gid=(select gid from ugrade where gname='计算机科学与技术3班')
5.
--理学院新开一门课程“数学建模”,课程编号20, 学分4,学时72,选修课程,最多选课人数为50.
insert into ucourse
select '20', '数学建模', '4', null, 72, '选修', 50, did
from udept where dname='理学院'
6.
--将李飞同学的联系方式改为660101
update ustudent
set stele='660101'
where sname='李飞'
7.
--6. 计算所有学生的总评成绩,公式为:总评=平时*20%+实验*20%+期末*60%
update usc
set score = score1*0.2+score2*0.2+score3*0.4
8.
--将电子信息1班(班级编号:08)的班主任改为洪玉飞老师(无重名)
update ugrade
set tid = (select tid from uteacher where tname='洪玉飞')
where gid='08'
9.
--将课程“数据库”的上课教室改为NB111,授课教师改为李飞(教师编号:02001)
update ujobtable
set tid='02001', room='NB111'
where cid=(select cid from ucourse where cname='数据库')
10.
--将学号为012005001的学生班级改为计算机科学与技术3班
update ustudent
set gid = (select gid from ugrade where gname='计算机科学与技术3班')
where sid='012005001'
11. 删除所有期末成绩小于60分的选课记录
delete from usc where score2<60
12. 删除学号为012005001的所有选课记录
delete from usc where sid='012005001'
13. 删除所有选修了”数据库”课程的选课记录
delete from usc where cid=(select cid from ucourse where cname='数据库')
14. 删除李飞老师(教师编号:02001)2008学年的排课记录
delete from ujobtable where tid='02001' and term in ('2007-2008-2', '2008-2009-1')
15. 删除所有在NB1楼上课的排课记录
delete from ujobtable where room like 'NB1%'
16. 删除NB111教室在周四的排课记录
delete from ujobtable where room='NB111' and week='4'
17. 删除选修人数小于5的选课记录
delete from ucourse where cid in (select cid from usc group by cid having count(cid)<5)
18. ---删除未担任班导师并且未安排课程的教师记录
delete from uteacher
where tid not in (select tid from ugrade where tid is not null) and tid not in (select tid from ujobtable)