A view definition can refer to other objects including columns, tables, and other views. When a view makes a reference to another object, the view is called a referencing object and the object to which it refers is called a referenced object. Further, a referencing object can be considered dependent on the objects to which it refers.
The set of referenced objects for a given view includes all of the objects to which it refers, either directly or indirectly. For example, a view can refer to another view, which may itself refer to other views and tables.
Consider the following set of tables and views:
CREATE TABLE t1 ( c1 INT, c2 INT ); CREATE TABLE t2( c3 INT, c4 INT ); CREATE VIEW v1 AS SELECT * FROM t1; CREATE VIEW v2 AS SELECT c3 FROM t2; CREATE VIEW v3 AS SELECT c1, c3 FROM v1, v2;
The following view dependencies can be determined from the definitions above:
View v1 is dependent on each individual column of t1, and on t1 itself.
View v2 is dependent on t2.c3, and on t2 itself.
View v3 is dependent on columns t1.c1 and t2.c3, tables t1 and t2, and views v1 and v2.
The database server keeps track of columns, tables, and views referenced by any given view. The database server uses this dependency information to ensure that schema changes to referenced objects do not leave a referencing view in an invalid state. In the case of non-materialized views, the database server provides this guarantee by automatically recompiling all referencing views whenever schema changes are made to referenced objects. In the case of materialized views, schema changes to a referenced object are not permitted if the object has any enabled materialized views.
Following is a list of considerations for view dependencies:
A non-materialized view can reference tables or views.
A materialized view can only reference base tables.
Before you drop a table, or alter a table or view, you must disable or drop all dependent materialized views.
When you disable or drop a view, all dependent non-materialized views are automatically disabled.
The DISABLE VIEW DEPENDENCIES clause of the ALTER TABLE statement only disables non-materialized dependent views. Any dependent materialized views must be explicitly disabled or dropped.
Once you disable a view, it can only be re-enabled explicitly.
Unlike non-materialized views, which are disabled if a referenced object is disabled, materialized views can only be disabled explicitly.
View status
Dependencies and schema-altering changes
View dependency information in the catalog