Bird
0
0

Which of the following is the correct way to define a PostgreSQL view named active_orders that only shows orders with status = 'active' and enforces this condition on data changes?

easy📝 Syntax Q3 of 15
PostgreSQL - Views and Materialized Views
Which of the following is the correct way to define a PostgreSQL view named active_orders that only shows orders with status = 'active' and enforces this condition on data changes?
ACREATE VIEW active_orders AS SELECT * FROM orders WHERE status = 'active' WITH CHECK;
BCREATE VIEW active_orders AS SELECT * FROM orders WHERE status = 'active' CHECK OPTION;
CCREATE VIEW active_orders AS SELECT * FROM orders WHERE status = 'active' WITH CHECK OPTION;
DCREATE VIEW active_orders AS SELECT * FROM orders WHERE status = 'active' OPTION CHECK;
Step-by-Step Solution
Solution:
  1. Step 1: Recall the syntax for WITH CHECK OPTION

    The correct syntax appends WITH CHECK OPTION after the SELECT statement in the CREATE VIEW command.
  2. Step 2: Verify each option

    Only CREATE VIEW active_orders AS SELECT * FROM orders WHERE status = 'active' WITH CHECK OPTION; uses the exact correct syntax; others have incorrect keywords or order.
  3. Final Answer:

    CREATE VIEW active_orders AS SELECT * FROM orders WHERE status = 'active' WITH CHECK OPTION; -> Option C
  4. Quick Check:

    WITH CHECK OPTION follows the SELECT statement [OK]
Quick Trick: WITH CHECK OPTION goes at the end of the view definition [OK]
Common Mistakes:
  • Omitting WITH in WITH CHECK OPTION
  • Misplacing CHECK OPTION before WHERE clause
  • Using incorrect keywords like OPTION CHECK

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes