with check option的学习
-----------------------------------
A view is created with the following statement:
CREATE VIEW v1
AS SELECT col1, col2, col3, col4
FROM t1
WHERE col4 > 1000
WITH CHECK OPTION
What is the effect of the CHECK OPTION clause?
++++++++++++++++++++++++++++++++
 
A. Any row inserted or updated through view V1 must meet the condition that col4 > 1000.
 
student表:
95001 李勇 男 20 CS
95002 刘晨 女 21 IS
95003 王敏 女 18 MA
95004 张力 男 19 IS

建立视图IS_STUDENT显示“IS”系所有学生的学号、姓名、性别。
create view IS_STUDENT
as
select Sno,Sname,Ssex
from Student
where Sdept='IS'
with check option;

用insert语句向视图中插入元组('95009','王五','男'),查看基本表student表中插入的数据值。当没有加上with check option 的时候,可以成功插入,切插入到基本表的年龄和专业都是null。 当加上with check ooption 的时候,就插入失败了

通过有with check option选项的视图操作基表(只是面对单表,对连接多表的视图正在寻找答案),有以下结论:
首先视图只操作它可以查询出来的数据,对于它查询不出的数据,即使基表有,也不可以通过视图来操作。
1.对于update,有with check option,要保证update后,数据要被视图查询出来
2.对于delete,有无with check option都一样
4.对于insert,有with check option,要保证insert后,数据要被视图查询出来
对于没有where 子句的视图,使用with check option是多余的


插入后的数据,通过视图能够查询出来就符合WITH CHECK OPTION 否则就不符合