Bird
0
0

Which SQL statement correctly creates an updatable view named v_staff that selects staff_id and staff_name from the staff table?

easy📝 Syntax Q3 of 15
SQL - Views
Which SQL statement correctly creates an updatable view named v_staff that selects staff_id and staff_name from the staff table?
ACREATE VIEW v_staff AS SELECT staff_id, staff_name FROM staff;
BCREATE VIEW v_staff AS SELECT staff_id, staff_name FROM staff GROUP BY staff_id;
CCREATE VIEW v_staff AS SELECT staff_id, staff_name, COUNT(*) FROM staff;
DCREATE VIEW v_staff AS SELECT DISTINCT staff_id, staff_name FROM staff;
Step-by-Step Solution
Solution:
  1. Step 1: Identify the correct syntax for a simple view

    The view should select columns directly without aggregation or grouping.
  2. Step 2: Check each option

    CREATE VIEW v_staff AS SELECT staff_id, staff_name FROM staff; selects staff_id and staff_name directly from staff, which is valid and updatable.
    CREATE VIEW v_staff AS SELECT staff_id, staff_name FROM staff GROUP BY staff_id; uses GROUP BY, which makes the view non-updatable.
    CREATE VIEW v_staff AS SELECT staff_id, staff_name, COUNT(*) FROM staff; includes COUNT(*), an aggregate, making it non-updatable.
    CREATE VIEW v_staff AS SELECT DISTINCT staff_id, staff_name FROM staff; uses DISTINCT, which can prevent updates.
  3. Final Answer:

    CREATE VIEW v_staff AS SELECT staff_id, staff_name FROM staff; -> Option A
  4. Quick Check:

    Simple select without aggregation or DISTINCT [OK]
Quick Trick: Avoid GROUP BY, aggregates, or DISTINCT for updatable views [OK]
Common Mistakes:
MISTAKES
  • Including GROUP BY or aggregates in view definition
  • Using DISTINCT which can block updates
  • Selecting columns not directly from a single table

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes