Bird
0
0

A view is created as CREATE VIEW v AS SELECT id, name FROM users;. Later, the users table drops the name column. What happens when you query the view?

medium📝 Debug Q7 of 15
PostgreSQL - Views and Materialized Views
A view is created as CREATE VIEW v AS SELECT id, name FROM users;. Later, the users table drops the name column. What happens when you query the view?
AThe view continues to return old data including the dropped column
BThe view automatically updates to exclude the dropped column
CThe view returns NULL for the dropped column
DQuerying the view causes an error because the column no longer exists
Step-by-Step Solution
Solution:
  1. Step 1: Understand view dependency on base tables

    Views depend on the columns existing in the underlying tables at query time.
  2. Step 2: Effect of dropping a column used by the view

    If a column used by the view is dropped, querying the view causes an error due to missing column.
  3. Final Answer:

    Querying the view causes an error because the column no longer exists -> Option D
  4. Quick Check:

    Dropped column breaks view query = A [OK]
Quick Trick: Dropping columns used in views breaks those views [OK]
Common Mistakes:
  • Assuming views auto-update columns
  • Expecting NULL instead of error
  • Thinking views cache old data

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes