数据库实验二

内容

  1. 使用insert语句将教材中的数据添加到studentdb中

  2. 将教材P71表中的数据添加到数据库SPJDB中

  3. 删除student表中学号为201215121的学生,体会执行删除操作时检查参照完整性规则的效果.将参照完整性中的删除规则改为“级联”(CASCADE),重新删除该学生信息。

  4. 更新student表中201215122学生的新学号为201215128,体会执行更新操作时检查参照完整性规则的效果.将参照完整性中的更新规则改为“级联”,重新更新该学生信息。

  5. 设计一组更新操作, 它需要另外一个表中的数据作为更新条件(如将选修了“信息系统”课程的成绩均提高15% )。

  6. 设计一个删除操作,它需要另外一个表中的数据作为删除条件(如将“刘晨”的选课记录删除 )。

  7. 完成教材P130页习题4和习题5中(1)~(7)的查询。

  8. 完成以下查询:

       (1)查询所有课程都及格的学生信息。
    

    (2)统计每一门课程的最高分、最低分和平均分。

    (3)从course表中查询课程名中包含“数据”二字的课程的信息。

    (4)统计所有学生3号课程的平均成绩,要求某个学生3号课程成绩为NULL,如不存在空值,请先插入。

    (5)查询每个学生及其选修课情况,显示学生姓名、课程名称和成绩,要求使用外连接输出所有学生和所有课程的信息。

    (6)查询所有学生中平均成绩最高的那个学生的学号。

    (7)查询只选修了2号课程的学生的信息,可以使用集合查询。

    (8)查询所有计算机系学生的学号、选修课程号以及分数。(使用IN谓词)。

    (9)查询选修了课程名为“操作系统”的学生学号和姓名。

    (10)查询所有计算机系学生的学号、选修课程号以及分数(使用EXISTS谓词)。

代码

1-7

/*单条插入*/
INSERT into student202020
    (sno,sname,ssex,sage,sdept)
values
    ('201215121', '李勇', '男', '20', 'CS')
INSERT into student202020
    (sno,sname,ssex,sage,sdept)
values
    ('201215122', '刘晨', '女', '19', 'CS')
INSERT into student202020
    (sno,sname,ssex,sage,sdept)
values
    ('201215123', '王敏', '女', '18', 'MA')
INSERT into student202020
    (sno,sname,ssex,sage,sdept)
values
    ('201215124', '张立', '男', '19', 'IS')
/*SC表和cours表图形化界面*/
/*3 4*/
delete from student202020  where sno='201215121';
update student202020  set sno ='201215128' where sno='201215122';
/*5*/
update sc202020  set grade = (1+0.15)*grade 
where cno = (select cno
from course202020
where cname='信息系统');
/*6*/
delete from sc202020  where sno=(select sno
from student202020
where sname='刘晨')
/*7*/
select sno
from SPJ202020
where jno='J1';
select sno
from SPJ202020
where jno='J1' and pno='P1';
select sno
from SPJ202020 , P202020
where SPJ202020 .pno =P202020 .pno and jno='J1' and color='红';
select jno
from J202020
where jno not in(select jno
from S202020  , P202020  , SPJ202020
where
S202020 .sno=SPJ202020  .sno and P202020 .pno=SPJ202020 .pno and color='红' and city='天津')
select distinct jno
from SPJ202020
where sno='S1';

select sname, city
from S202020
;
select pname, color, weight
from P202020
;
select jno
from SPJ202020
where sno='S1';
select pname, qty
from SPJ202020  , P202020
where SPJ202020 .pno =P202020  .pno and jno='J2';
select distinct pno
from S202020  , spj202020
where s202020 .sno=s202020 .sno and city='上海';
select jname
from S202020 , J202020 , SPJ202020
where S202020 .sno=SPJ202020 .sno and
    J202020 .jno=SPJ202020 .jno and s202020 .city='上海';
select jno
from J202020
where jno not in (select jno
from S202020  , SPJ202020
where s202020 .sno=spj202020 .sno
    and city='天津');
update P202020  set color='蓝' where color='红';
/*8*/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值