1.创建视图
(1)创建一个名为 stuview2 的水平视图,从数据库 student info 的 Student 表中查询出性别为“
男”的所有学生的资料。并在创建视图时使用 with check option。(注:该子句用于强制视图上执行的所
有修改语句必须符合由 select 语句 where 中的条件。)
解释:WITH CHECK OPTION 的作用?
1.对于 update,有 with check option,要保证 update 后,数据要被视图查询出来;
2.对于 delete,有无 with check option 都一样;
4.对于 insert,有 with check option,要保证 insert 后,数据要被视图查询出来;
5.对于没有 where 子句的视图,使用 with check option 是多余的。
语句:
create view stuview2
as
select * from student where sex='男'
with check option
查看视图:
语句:
select * from stuview2
(2)创建一个名为 stuview3 的投影视图,从数据库 student_info 的 Course 表中查询学分大于 3 的
所有课程的课程号、课程名、总学时。并在创建时对该视图加密。(提示:用 with ENCRYPTION 关键子句
)
语句:
create view stuview3 with ENCRYPTION
as
select Cno , Cname , Total_perior from course where credit>3
(3)创建一个名为 stuview4 的视图,能检索出“051”班所有女生的学号、课程号及相应的成绩。
create view stuview4
as
select * from sc
where sno=(
select sno from student
where classno='051' and sex='女')
(4)创建一个名为 stuview5 的视图,能检索出每位选课学生的学号、姓名、总成绩。
create view stuview5
as
select student.sno 学号,sname 姓名 ,Grade 成绩 from student,sc
where student.Sno=sc.sno
2.查询视图的创建信息及视图中的数据
(1)查看视图 stuview2 的创建信息。