Bird
0
0

If you want to change the query of a view named employee_details to include only employees from the 'HR' department, which SQL command will produce the correct output?

medium📝 query result Q5 of 15
SQL - Views
If you want to change the query of a view named employee_details to include only employees from the 'HR' department, which SQL command will produce the correct output?
ADROP VIEW employee_details; CREATE VIEW employee_details AS SELECT * FROM employees WHERE department = 'HR';
BMODIFY VIEW employee_details AS SELECT * FROM employees WHERE department = 'HR';
CUPDATE VIEW employee_details SET query = 'SELECT * FROM employees WHERE department = ''HR''';
DALTER VIEW employee_details AS SELECT * FROM employees WHERE department = 'HR';
Step-by-Step Solution
Solution:
  1. Step 1: Check ALTER VIEW support

    Not all SQL systems support ALTER VIEW to redefine a view; often DROP and CREATE is used.
  2. Step 2: Analyze options

    DROP VIEW employee_details; CREATE VIEW employee_details AS SELECT * FROM employees WHERE department = 'HR'; drops the old view and creates a new one with the desired query, which works universally. ALTER VIEW employee_details AS SELECT * FROM employees WHERE department = 'HR'; may fail if ALTER VIEW is unsupported. Options B and C use invalid syntax.
  3. Final Answer:

    DROP VIEW employee_details; CREATE VIEW employee_details AS SELECT * FROM employees WHERE department = 'HR'; -> Option A
  4. Quick Check:

    Drop and recreate view to change query = D [OK]
Quick Trick: Drop and recreate view if ALTER VIEW is unsupported [OK]
Common Mistakes:
MISTAKES
  • Assuming ALTER VIEW always works
  • Using UPDATE or MODIFY VIEW which are invalid
  • Not recreating view after drop

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes