Bird
0
0

You created a view with this SQL:

medium📝 Debug Q14 of 15
PostgreSQL - Views and Materialized Views
You created a view with this SQL:
CREATE VIEW emp_dept AS SELECT e.id, e.name, d.name AS dept_name FROM employees e JOIN departments d ON e.dept_id = d.id;
When you try to update emp_dept to change an employee's name, you get an error. What is the main reason?
AThe view joins multiple tables, so it is not automatically updatable
BThe view does not include the employee's ID column
CThe view uses aliases for columns, causing syntax errors
DThe view is missing a WHERE clause
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the view definition

    The view joins two tables: employees and departments.
  2. Step 2: Understand updatable view rules for joins

    Views that join multiple tables are not automatically updatable in PostgreSQL because the system cannot decide how to update multiple tables from one view.
  3. Final Answer:

    The view joins multiple tables, so it is not automatically updatable -> Option A
  4. Quick Check:

    Joined views are not updatable by default [OK]
Quick Trick: Views with joins are not updatable automatically [OK]
Common Mistakes:
  • Thinking missing ID causes update failure
  • Blaming column aliases for errors
  • Assuming WHERE clause is required for updates

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes