Bird
0
0

Given the view definition:

medium📝 query result Q13 of 15
SQL - Views
Given the view definition:
CREATE VIEW dept_salary AS SELECT department_id, AVG(salary) AS avg_salary FROM employees GROUP BY department_id;

Which of the following statements is true when trying to update avg_salary through this view?
AYou can update <code>avg_salary</code> directly and it will change salaries in employees.
BYou cannot update <code>avg_salary</code> because the view uses aggregation.
CUpdating <code>avg_salary</code> will update all salaries in the department equally.
DThe view allows updates only if you use INSTEAD OF triggers.
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the view's use of aggregation

    The view uses AVG() and GROUP BY, which creates a summary, not individual rows.
  2. Step 2: Understand update limitations on aggregated views

    Aggregated columns like avg_salary cannot be updated directly because they do not map to single rows.
  3. Final Answer:

    You cannot update avg_salary because the view uses aggregation. -> Option B
  4. Quick Check:

    Aggregated views are not updatable by default [OK]
Quick Trick: Aggregated views block direct updates [OK]
Common Mistakes:
MISTAKES
  • Trying to update aggregate columns
  • Assuming updates affect underlying rows automatically
  • Ignoring need for triggers on complex views

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes