Bird
0
0

Consider the view:

medium📝 Debug Q7 of 15
PostgreSQL - Views and Materialized Views
Consider the view:
CREATE VIEW premium_members AS SELECT * FROM members WHERE membership_level = 'premium' WITH CHECK OPTION;
Why would an attempt to update a member's membership_level from 'premium' to 'basic' through this view fail?
ABecause the updated row would no longer satisfy the view's WHERE condition, violating the CHECK OPTION.
BBecause views with CHECK OPTION do not allow any updates.
CBecause the base table does not permit updates on the membership_level column.
DBecause the view does not include the membership_level column.
Step-by-Step Solution
Solution:
  1. Step 1: Understand the view's condition

    The view only includes rows where membership_level = 'premium'.
  2. Step 2: Analyze the update attempt

    Changing membership_level to 'basic' would exclude the row from the view.
  3. Step 3: Effect of WITH CHECK OPTION

    WITH CHECK OPTION prevents updates that cause rows to no longer satisfy the view's condition.
  4. Final Answer:

    Because the updated row would no longer satisfy the view's WHERE condition, violating the CHECK OPTION. -> Option A
  5. Quick Check:

    Updates must keep rows within view condition [OK]
Quick Trick: Updates violating view condition are rejected [OK]
Common Mistakes:
  • Assuming CHECK OPTION disallows all updates
  • Blaming base table constraints without checking view condition
  • Thinking the view excludes membership_level column

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes