Example: Cascaded check option

 

This example shows how the check option is enforced on a number of dependent views that are defined with or without a check option.

Use the following table and views:

     CREATE TABLE T1 (COL1 CHAR(10))
 
     CREATE VIEW  V1 AS SELECT COL1
           FROM T1 WHERE COL1 LIKE 'A%'
 
     CREATE VIEW V2 AS SELECT COL1
           FROM V1 WHERE COL1 LIKE '%Z'
                                  WITH LOCAL CHECK OPTION
 
     CREATE VIEW V3 AS SELECT COL1
           FROM V2 WHERE COL1 LIKE 'AB%'
 
     CREATE VIEW V4 AS SELECT COL1
           FROM V3 WHERE COL1 LIKE '%YZ'
                                   WITH CASCADED CHECK OPTION
 
     CREATE VIEW V5 AS SELECT COL1
           FROM V4 WHERE COL1 LIKE 'ABC%'

Different search conditions are going to be checked depending on which view is being operated on with an INSERT or UPDATE statement.

If V5 were created WITH LOCAL CHECK OPTION, operating on V5 means that COL1 must start with 'ABC' and end with 'YZ'. The LOCAL CHECK OPTION adds the additional requirement that the third character must be a 'C'.

 

Parent topic:

WITH CHECK OPTION on a view