`
luzl
  • 浏览: 577355 次
  • 性别: Icon_minigender_1
  • 来自: 大连
社区版块
存档分类
最新评论

DB2创建VIEW的时候CHECK OPTION的作用

    博客分类:
  • DB2
阅读更多
创建视图的时候有几种CHECK OPTION
CHECK OPTION
CASCADED CHECK OPTION
LOCAL CHECK OPTION

看看这个例子:
------------------------------ Commands Entered ------------------------------
CREATE TABLE tab1 (col1 SMALLINT );
CREATE VIEW v1 AS SELECT col1 FROM tab1 WHERE col1 > 20 ;
CREATE VIEW v2L AS SELECT col1 FROM v1 WITH LOCAL CHECK OPTION ;
CREATE VIEW v2C AS SELECT col1 FROM v1 WITH CASCADED CHECK OPTION ;
CREATE VIEW v3L AS SELECT col1 FROM v2L WHERE col1 < 50 ;
CREATE VIEW v3C AS SELECT col1 FROM v2C WHERE col1 < 50 ;
------------------------------------------------------------------------------
DB20000I  The SQL command completed successfully.

DB20000I  The SQL command completed successfully.

DB20000I  The SQL command completed successfully.

DB20000I  The SQL command completed successfully.

DB20000I  The SQL command completed successfully.

DB20000I  The SQL command completed successfully.

------------------------------ Commands Entered ------------------------------
INSERT INTO v1 VALUES (10);
------------------------------------------------------------------------------
DB20000I  The SQL command completed successfully.

------------------------------ Commands Entered ------------------------------
INSERT INTO v2L VALUES (5);
------------------------------------------------------------------------------
DB20000I  The SQL command completed successfully.

------------------------------ Commands Entered ------------------------------
INSERT INTO v2C VALUES (5);
------------------------------------------------------------------------------
INSERT INTO v2C VALUES (5)
DB21034E  The command was processed as an SQL statement because it was not a 
valid Command Line Processor command.  During SQL processing it returned:
SQL0161N  The resulting row of the insert or update operation does not conform 
to the view definition.  SQLSTATE=44000


------------------------------ Commands Entered ------------------------------
INSERT INTO v3L VALUES (50);
INSERT INTO v3C VALUES (50);
------------------------------------------------------------------------------
DB20000I  The SQL command completed successfully.

DB20000I  The SQL command completed successfully.

------------------------------ Commands Entered ------------------------------
INSERT INTO v3L VALUES (100);
INSERT INTO v3C VALUES (100);
------------------------------------------------------------------------------
DB20000I  The SQL command completed successfully.

DB20000I  The SQL command completed successfully.

CASCADED CHECK OPTION 的作用是让当前创建的视图继承它使用到的视图的过滤条件,其他就没有什么区别了,都是为了阻止INSERT和UPDATE不符合过滤条件的数据。
分享到:
评论

相关推荐

    db2认证 000-541,102q

    CREATE VIEW V2 AS SELECT COI1 FROM v1 WITH CASCADED CHECK OPTION CREATE VIEW v3 AS SELECT coll FROM v2 WHERE coll ; Which statement will fail? A. INSERT INTO v2 VALUES (35) B. INSERT INTO v1 VALUES ...

    IBM DB2 700 考试真题库 附答案

    选项D,带检查选项的视图(View with check option),限制插入或更新数据时必须满足的条件。选项A,索引,是提高查询性能的结构,而非约束;选项B,存储过程,是一组预编译的SQL语句,不是用来限制插入值的;选项E...

    DB2 V9.7 认证 000-541

    `WITH CASCADED CHECK OPTION`属性用于确保在试图插入数据到底层视图时,必须满足所有上层视图的筛选条件。 **知识点解析:** - **数据插入失败分析**:在给出的代码示例中,当尝试向`v3`视图插入值为25的记录时,...

    IBM 000-541认证题库

    CREATE VIEW V2 AS SELECT COI1 FROM v1 WITH CASCADDED CHECK OPTION; CREATE VIEW v3 AS SELECT col FROM v2 WHERE col ; ``` **问题:** 哪个插入语句会失败? A. INSERT INTO v2 VALUES(35) B. INSERT INTO v1 ...

    oracle学习文档 笔记 全面 深刻 详细 通俗易懂 doc word格式 清晰 连接字符串

    在创建表时,经常会创建该表的主键、外键、唯一约束、Check约束等  语法结构 create table 表名( [字段名] [类型] [约束] ……….. CONSTRAINT fk_column FOREIGN KEY(column1,column2,…..column_n) ...

Global site tag (gtag.js) - Google Analytics