Bird
0
0

A developer creates a view with CREATE VIEW emp_view AS SELECT id, name FROM employees; but gets an error when trying to update it. What could be a likely cause?

medium📝 Debug Q7 of 15
PostgreSQL - Views and Materialized Views
A developer creates a view with CREATE VIEW emp_view AS SELECT id, name FROM employees; but gets an error when trying to update it. What could be a likely cause?
AThe employees table has no primary key defined.
BThe view uses SELECT * instead of explicit columns.
CThe view includes a WHERE clause filtering rows.
DThe view is created with the WITH CHECK OPTION.
Step-by-Step Solution
Solution:
  1. Step 1: Check requirements for updatable views

    PostgreSQL requires the underlying table to have a primary key or unique index for updates through views.
  2. Step 2: Analyze the cause of error

    If employees table lacks a primary key, updates through the view will fail.
  3. Final Answer:

    The employees table has no primary key defined. -> Option A
  4. Quick Check:

    Primary key needed for updatable views [OK]
Quick Trick: Ensure base table has primary key for updatable views [OK]
Common Mistakes:
  • Thinking SELECT * causes update errors
  • Assuming WHERE clause blocks updates
  • Confusing WITH CHECK OPTION with update errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes