Bird
0
0

Given the table employees(id, name, salary) and the view:

medium📝 query result Q13 of 15
PostgreSQL - Views and Materialized Views
Given the table employees(id, name, salary) and the view:
CREATE VIEW high_salary AS SELECT * FROM employees WHERE salary > 5000 WITH CHECK OPTION;
What happens if you try to insert (10, 'Anna', 4000) into high_salary?
AThe insert fails due to the CHECK OPTION
BThe insert succeeds but the row is not visible in the view
CThe insert succeeds and adds the row
DThe insert causes a syntax error
Step-by-Step Solution
Solution:
  1. Step 1: Understand the view filter and CHECK OPTION

    The view only shows employees with salary > 5000, and WITH CHECK OPTION prevents inserts that don't meet this.
  2. Step 2: Analyze the insert data

    The salary 4000 is less than 5000, so the insert violates the view's filter and is blocked.
  3. Final Answer:

    The insert fails due to the CHECK OPTION -> Option A
  4. Quick Check:

    Insert violating view filter blocked = C [OK]
Quick Trick: Insert must meet view filter or it fails [OK]
Common Mistakes:
  • Thinking insert always succeeds
  • Assuming row is added but hidden
  • Confusing syntax error with runtime error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes