create or replace view myview1
as
select * from student where ssex='女'
插入第一条数据
insert into myview1 values(09,'王五','1994-07-10','女')
select * from myview1
运行结果:视图中新增一条数据
insert into myview1 values(10,'二麻子','1995-07-10','男')
运行结果:运行成功
with check option作用:对视图所做的DML操作的结果,不能违反视图的WHERE条件的限制。
create or replace view myview1
as
select * from student where ssex='女'
with check option
insert into myview1 values(11,'二麻子1','1995-08-10','男')
运行后结果为:
1、修改第一条数据,修改成功
update myview1 set sname='刘六' where sid=09
2、修改第二条数据,修改失败
update myview1 set ssex='男' where sid=09
提示:> 1369 - CHECK OPTION failed 'student1.myview1
1、对于update,有with check option,要保证update后,数据要被视图查询出来
2、对于delete,有无with check option都一样
3、对于insert,有with check option,要保证insert后,数据要被视图查询出来
4、对于没有where 子句的视图,使用with check option是多余的