WITH LOCAL CHECK OPTION

 

The WITH LOCAL CHECK OPTION clause is identical to the WITH CASCADED CHECK OPTION clause except that you can update a row so that it can no longer be retrieved through the view. This can happen only when the view is directly or indirectly dependent on a view that was defined with no WITH CHECK OPTION clause.

For example, consider the same updatable view used in the previous example:

     CREATE VIEW V1 AS SELECT COL1
               FROM T1 WHERE COL1 > 10

Create second view over V1, this time specifying WITH LOCAL CHECK OPTION:

     CREATE VIEW V2 AS SELECT COL1
               FROM V1 WITH LOCAL CHECK OPTION

The same INSERT statement that failed in the previous CASCADED CHECK OPTION example succeeds now because V2 does not have any search conditions, and the search conditions of V1 do not need to be checked since V1 does not specify a check option.

     INSERT INTO V2 VALUES (5)

Consider one more view created over V2:

     CREATE VIEW V3 AS SELECT COL1
          FROM V2 WHERE COL1 < 100

The following INSERT is successful again because the search condition on V1 is not checked due to the WITH LOCAL CHECK OPTION on V2, versus the WITH CASCADED CHECK OPTION in the previous example.

     INSERT INTO V3 VALUES (5)

The difference between LOCAL and CASCADED CHECK OPTION lies in how many of the dependent views' search conditions are checked when a row is inserted or updated.

 

Parent topic:

WITH CHECK OPTION on a view