实验内容及结果 |
一、基本表操作
1.建立基本表
创建教材中的学生表(student)、学生选课表(SC)、课程表(course)
1)·学生表:Student (Sno, Sname,Sage,Ssex,Sdept)其中学号Sno主码
2)·课程表:Course (Cno, Cname, Cpno, Ccredit)其中课程号Cno主码;先行课为外码参照Course表中Cno字段。
3)·学生选课表:SC(Sno, Cno, Grade)其中学号Sno、课程号Cno为主码;Sno为外码参照Student表中sno字段;Cno为外码参照Course表中cno字段。
2.修改基本表
1)在Student表中加入属性BloodType(char(2)型)。
Alter table Student ADD BLOODTYPE char(4);
2)修改表student中的Sdept属性的数据类型为varchar2(40),注意和定义表的时候类型不同。
3)给表student的sage列添加一个自定义约束sage必须大于15且小于30。
4)删除3)中新添加的约束。
5)删除表student中的字段BloodType。
3.删除基本表
1) 删除基本表Student
2)删除基本表SC
二、索引操作
1.建立索引
1)在Student表上建立关于Sname的唯一索引stusnam+学号后四位
2)在SC表上建立关于Sno升序、Cno降序的唯一索引i_sc+学号后四位
2.删除索引
drop Index stusnam_4508;
2)删除Course表上的索引i_sc+学号后四位
drop Index i_sc_4508;
(二)数据操作
一、数据更新
1.插入数据
1)向Student表中插入数据
Insert
INTO Student
Values('202113456','王敏','女','19','cs');
Insert
INTO Student
Values('201924155','刘晨','男','21','cs');
2)向Course表中插入数据
Insert
INTO Course(Cno,Cname,Ccredit)
Values('1','数学','2');
3)向SC表中插入数据
Insert
INTO SC
Values(201924155,1,92);
2.修改数据
1)将王敏的同学的年龄改为20。
update student
set sage=20
where sname='王敏';
2)将全部同学的年龄加1。
update student
set sage=sage+1;
3)将’CS’系同学的选课信息中的成绩置0。
update sc
set grade=0
where sno in(select sno
from student
where sdept='cs');
3.删除数据
1)删除和’ 刘晨’在同一个系的学生的信息。
delete
from student
where sdept in(Select sdept
from student
where sname='刘晨');
delete
from sc
where sno in(Select sno
from student
where sdept='cs');