zoukankan      html  css  js  c++  java
  • with check option

     
    -----------------------------------

    create table student
    (sno char(9) primary key,
    sname char(20) unique,
    ssex char(2),
    sage smallint,
    sdept char(20)
    );

    insert into student values ('95001','李勇','男','20','CS')
    insert into student values ('95002','刘晨','女','19','IS')
    insert into student values ('95003','王敏','女','18','MA')
    insert into student values ('95004','张立','男','19','IS')
    insert into student values ('95005','王强','男','20','IS')
    insert into student values ('95015','张三','男','19','CS')
    insert into student values ('95019','李四','男','18','CS')
    insert into student values ('95020','陈冬','男','19','IS')

     

    建立视图IS_STUDENT显示“IS”系所有学生的学号、姓名、性别。
    CREATE VIEW IS_Student
    AS
    SELECT Sno,Sname,Sage
    FROM Student
    WHERE Sdept='IS'
    WITH CHECK OPTION

    用insert语句向视图中插入元组

    INSERT
    INTO IS_Student
    VALUES ('95029','赵信',20);查看基本表student表中插入的数据值。当没有加上with check option 的时候,可以成功插入,切插入到基本表的年龄和专业都是null。 当加上with check ooption 的时候,就插入失败了

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


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

  • 相关阅读:
    树链剖分求LCA
    洛谷P1019 单词接龙
    洛谷P1441 砝码称重
    洛谷P2347 砝码称重
    洛谷P1164 小A点菜
    洛谷P2202 [USACO13JAN]方块重叠Square Overlap
    黑客与画家 第四章
    黑客与画家 第十二章
    记录最近一段的体会
    11.5最小生成树(Minimum Spanning Trees)
  • 原文地址:https://www.cnblogs.com/liwon/p/3399703.html
Copyright © 2011-2022 走看看