Bird
0
0

Which of the following is the correct syntax to create a simple updatable view on a single table employees showing id and name columns?

easy📝 Syntax Q12 of 15
PostgreSQL - Views and Materialized Views
Which of the following is the correct syntax to create a simple updatable view on a single table employees showing id and name columns?
ACREATE VIEW emp_view AS SELECT id, name FROM employees;
BCREATE VIEW emp_view AS UPDATE employees SET name = 'John';
CCREATE TABLE emp_view AS SELECT id, name FROM employees;
DCREATE FUNCTION emp_view() RETURNS TABLE(id INT, name TEXT) AS $$ SELECT id, name FROM employees; $$ LANGUAGE SQL;
Step-by-Step Solution
Solution:
  1. Step 1: Recall the syntax to create a view

    The syntax is CREATE VIEW view_name AS SELECT columns FROM table;
  2. Step 2: Check each option

    CREATE VIEW emp_view AS SELECT id, name FROM employees; matches the correct syntax for a simple view. The other options are incorrect because they use UPDATE, CREATE TABLE, or FUNCTION instead of CREATE VIEW.
  3. Final Answer:

    CREATE VIEW emp_view AS SELECT id, name FROM employees; -> Option A
  4. Quick Check:

    CREATE VIEW uses SELECT query [OK]
Quick Trick: CREATE VIEW uses SELECT, not UPDATE or TABLE [OK]
Common Mistakes:
  • Using UPDATE instead of SELECT in CREATE VIEW
  • Confusing CREATE VIEW with CREATE TABLE
  • Trying to create a function instead of a view

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes