#第7章
#【例7.1】在stusys数据库中创建V_StudentScore视图,包括学号、姓名、性别、专业、课程号、成绩,且专业为计算机。
use stusys;
create view V_StudentScore
as
select a.sno as 学号,a.sname as 姓名,ssex as 性别,speciality as 专业,b.cno as 课程号,grade 成绩
from student a,score b
where a.speciality='计算机';
select * from V_StudentScore;
#【例7.2】在stusys数据库中创建V_StudentCourseScore视图,包括学号、姓名、性别、课程名、成绩,按学号升序排列,且专业为计算机。
use stusys;
create view V_StudentCourseScore
as
select a.sno as 学号,a.sname as 姓名,a.ssex as 性别,b.cname as 课程名,c.grade 成绩
from student a,course b,score c
where a.sno=c.sno and b.cno=c.cno and a.speciality='计算机'
order by a.sno;
select * from V_StudentCourseScore;
#【例7.3】 分别查询V_StudentScore视图、V_StudentCourseScore视图。
select * from V_StudentScore;
select * from V_StudentCourseScore;
#【例7.4】 查询计算机专业学生的学号、姓名、性别、课程名。
use stusys;
select 学号,姓名,性别,课程名 from V_StudentCourseScore;
#【例7.5】在stusys数据库中,以student为基表,创建专业为通信的可更新视图
use stusys;
create view V_StudentSpecialityComm
as
select a.sno as 学号,a.sname as 姓名,ssex as 性别,speciality as 专业,b.cno as 课程号,grade 成绩
from student a,score b
where a.speciality='通信'and a.sno=b.sno;
#【例7.6】 向V_StudentSpecialityComm视图中插入一条记录:('196006','程超','男','1998-04-28','通信', 50)。
use stusys;
alter view V_StudentSpecialityComm
as
select sno as 学号,sname as 姓名,ssex as 性别,sbirthday as 出生日期,speciality as 专业,tc as 学分
from student
where speciality='通信';
insert into V_StudentSpecialityComm
values('196006','程超','男','1998-04-28','通信', 50);
#【例7.7】 将V_StudentSpecialityComm视图中学号为196006的学生的总学分增加2分。
use stusys;
update V_StudentSpecialityComm set 学分=学分+2
where 学号='196006';
select * from score;
select * from student;
#【例7.8】 删除V_StudentSpecialityComm视图中学号为196006的记录。
use stusys;
delete from V_StudentSpecialityComm
where 学号='196006';
select * from V_StudentSpecialityComm
#【例7.9】 将例7.1定义的视图V_StudentScore视图进行修改,取消专业为计算机的要求。
#【例7.10】修改例7.2创建的视图V_StudentCourseScore,学号以降序排列。
#【例7.11】 在stusys数据库中,将视图V_StudentCourseScore删除。
use stusys;
drop view V_StudentCourseScore;
#【例7.12】 在stusys数据库中student表的sname列上,创建一个普通索引I_studentSname。
use stusys;
cr
————————————————
版权声明:本文为CSDN博主「君诀210」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_62981698/article/details/130523104