2023年6月27日发(作者:)
桂林航天工业学院学生实验报告
实验五
实验名称 数据更新和视图
1.熟悉INSERT语句的使用
2.熟悉UPDATE语句使用
实验目的
3.熟悉DELETE语句使用
4.熟悉建立视图语句使用
实验内容 数据更新、视图
实验日期 2019.10.24
实验步骤及结论
1、建立计算机系学生的视图CS_Student。
create view CS_student As select sno,sname,ssex,sdept,sage
from student where sdept='CS'
select * from CS_student
select * from student
2、通过视图IS_Student插入一个新学生元组(学号:201215131;姓名:陈伟;性别:男;所在系:CS ;年龄:18岁)。
insert into CS_student (sno,sname,ssex,sdept,sage) values('201215131','陈伟','男','CS','18')
1
3、建立选了课,但缺少成绩的学生的学号和相应课程号的视图nullgrade。
create view nullgrade As select sno,cno, grade
from sc where (cno IS NOT NULL and grade is null)
select * from nullgrade
select * from
sc
4、通过视图nullgrade插入一个选课记录(学号:201215131;课程号:1)。
insert into nullgrade (sno,cno) values('201215131','1')
select * from nullgrade
5、对每一门课求平均成绩,并把结果存入数据库中。(参照例3.72)
create table Dept_grade
(sdept CHAR(15),Avg_grade SMALLINT)
insert into Dept_grade (sdept,Avg_grade) select cno,AVG(grade)
from SC group by cno
select * from Dept_grade
2 6、将学生201215121所在的系改为MA,并用SELECT语句查看更改的结果。
UPDATE student set sdept='MA'
where sno='201215121';
select * from student
7、将所有学生的年龄减少1岁。
select * from student
update student set sage=sage-1
select * from student
8、通过视图nullgrade删除学号为201215131的学生的选课记录。
select * from nullgrade
DELETE from nullgrade
where sno='201215131'
3
9、将Student表中学生号为201215121的学生所属的系改为空值。
update student set sdept=null where sno='201215121'
select * from student
10、建立计算机系选修了1号课程且成绩在90分以上的学生的视图IS_S2。
create view cs_s2(sno,sname,grade)
as
select ,sname,grade
from student,sc
where sdept='cs'and = and ='1' and >=90;
select * from cs_s2
4 11、建立学生姓名、课程名称、成绩的视图。
create view sname_cname_grade (sname,cno,grade)
as
select ,,
from student,course,sc
where = and =;
select * from sname_cname_grade
12、将各门课程及平均成绩定义为一个视图。
create view cno_avg_grade(cno,cname,Avg_grade)
as
select Dept_,,Dept__grade
from course,Dept_grade
where Dept_=;
select * from cno_avg_grade
5
6
发布者:admin,转转请注明出处:http://www.yc00.com/web/1687816054a47607.html
评论列表(0条)