SNOWPRO-CORE practice question 35 of 35

A view is defined on a permanent table. A temporary table with the same name is created in the same schema as the referenced table. What will the query from the view return?

Full set: 628 questions

Domain Storage and Protection

Answer options
A: The data from the permanent table. Correct answer
B: The data from the temporary table.
C: An error stating that the view could not be compiled.
D: An error stating that the referenced object could not be uniquely identified.
Correct Answer:
A. The data from the permanent table.
Explanation

A view's definition is resolved and bound to its underlying database objects at the time of its creation. The query definition is stored in the data dictionary, referencing the specific permanent table that existed when the CREATE VIEW statement was executed. The subsequent creation of a temporary table, even with the same name and in the same schema, does not alter this stored definition. Therefore, when the view is queried, it will execute its original, bound query, which accesses the data from the permanent table.

Why Incorrect

B. The temporary table takes precedence for direct queries on the table name within the session, but it does not retroactively change the static definition of a pre-existing view.
C. The view remains valid because its underlying permanent table still exists. The creation of a new temporary table does not invalidate the view or cause a compilation error.
D. There is no ambiguity from the view's perspective. Its definition was uniquely resolved and bound to the permanent table at the time of its creation.

References

1. Snowflake Documentation: Overview of Views

Reference: Docs > Working with Views > Overview of Views

Content: "The definition of a view is static. If the underlying source for the view changes in a way that is inconsistent with the view definition, the view becomes invalid. For example, if a column is dropped from the source table, the view becomes invalid." This confirms the static nature of the view's definition, which is bound at creation.

2. Snowflake Documentation: CREATE VIEW

Reference: Docs > SQL Command Reference > DDL (Data Definition Language) > CREATE VIEW

Content: "The SELECT statement for the view is stored in the data dictionary." This indicates that the query logic is fixed and stored upon creation, rather than being dynamically interpreted at runtime.

3. Snowflake Documentation: Name Resolution

Reference: Docs > SQL Command Reference > General Usage Notes > Name Resolution

Content: "When a temporary table has the same name as a permanent table in the same schema, the temporary table takes precedence within the session. All queries and operations on the table within the session affect the temporary table." This rule applies to direct queries on the object name, not to queries that execute through a view whose definition was already bound to the permanent table.

Scroll to Top