• with check option


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

    以例子验证结论:
    --创建表
    create table emp(
        id number(5,0),
        name varchar2(12),
        address varchar2(12)
    );
    insert into emp values (5,'張三','廣西');
    insert into emp values (6,'李四','北京');
    insert into emp values (7,'王五','山東');

    --创建带with check option的视图
    create view emp_view
    as
    select * from emp where id=5
    with check option;

    --创建没有with check option的视图
    create view emp_view2
    as
    select * from emp where id='5'
    --update 操作
    update  emp_view set  name='陈六' where id=6;-,虽然基表有id=6的记录,但emp_view无法查看到,所以这个修改不会影响基表内容
    update  emp_view set  id=6 where id=5; --出现 view WITH CHECK OPTION where-clause violation错误
    update  emp_view2 set id=6 where id=5; --成功执/plain行
    --结论:
    --对于update,有无with选项都是只更改视图出现的記錄,对有whih选项的update,要保证更改后仍可以出现在视图中

    --把数据改回原型
    update  emp set id=5 where name='張三';

    --delete操作
    delete emp_view where id='5'
    --结论:
    --对于delete,有无with选项是一样的。

    --insert操作
    insert into emp_view values (8,'王','江蘇');--出现 view WITH CHECK OPTION where-clause violation错误
    insert into emp_view2 values (8,'王','江蘇');--执行成功
    --结论:
    --对于insert,有with选项,插入的数据要最终要可以显示在视图中,对于无with选项的视图可以插入任何不违反约束的记录

  • 相关阅读:
    继承中的虚函数、纯虚函数、普通函数
    struct与class的区别
    boost::filesystem总结
    ASM: Active Shape Models--Their Training and Application
    基础知识:仿射变换、相似变换、等距变换等常见变换
    PDM:Training Models of Shape from Sets of Examples
    常见优化器
    深度学习基础(五)ResNet_Deep Residual Learning for Image Recognition
    深度学习基础(四) Dropout_Improving neural networks by preventing co-adaptation of feature detectors
    ios 各种变量和作用范围
  • 原文地址:https://www.cnblogs.com/xtt321/p/4547770.html
Copyright © 2020-2023  润新知