Bird
0
0

You have a view defined as CREATE VIEW emp_view AS SELECT id, name FROM employees WHERE active = true; You want to ensure updates through this view only affect active employees. What is the best way?

hard📝 Application Q9 of 15
PostgreSQL - Views and Materialized Views
You have a view defined as CREATE VIEW emp_view AS SELECT id, name FROM employees WHERE active = true; You want to ensure updates through this view only affect active employees. What is the best way?
AAdd a trigger to prevent updates on inactive employees.
BAdd WITH CHECK OPTION to the view definition.
CRemove the WHERE clause to allow all updates.
DUse a materialized view instead.
Step-by-Step Solution
Solution:
  1. Step 1: Understand WITH CHECK OPTION

    This option restricts updates and inserts through the view to rows visible in the view.
  2. Step 2: Apply to the scenario

    Adding WITH CHECK OPTION ensures only active employees can be updated via the view.
  3. Final Answer:

    Add WITH CHECK OPTION to the view definition. -> Option B
  4. Quick Check:

    WITH CHECK OPTION enforces view row conditions on updates [OK]
Quick Trick: Use WITH CHECK OPTION to restrict updates in views [OK]
Common Mistakes:
  • Removing WHERE clause loses filtering
  • Assuming triggers are always needed
  • Confusing materialized views with update control

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes