Bird
0
0

Which sequence of commands correctly updates the view without losing it?

hard📝 Application Q15 of 15
SQL - Views
You have a view product_summary showing product names and total sales. You want to update it to include only products with sales over 500. Which sequence of commands correctly updates the view without losing it?
ADROP VIEW product_summary; CREATE VIEW product_summary AS SELECT name, SUM(sales) FROM products GROUP BY name HAVING SUM(sales) > 500;
BALTER VIEW product_summary AS SELECT name, SUM(sales) FROM products GROUP BY name HAVING SUM(sales) > 500;
CUPDATE VIEW product_summary SET query = 'SELECT name, SUM(sales) FROM products GROUP BY name HAVING SUM(sales) > 500;';
DREPLACE VIEW product_summary AS SELECT name, SUM(sales) FROM products GROUP BY name HAVING SUM(sales) > 500;
Step-by-Step Solution
Solution:
  1. Step 1: Understand how to update a view's query

    ALTER VIEW updates the query inside an existing view without dropping it.
  2. Step 2: Check each option's correctness

    ALTER VIEW product_summary AS SELECT name, SUM(sales) FROM products GROUP BY name HAVING SUM(sales) > 500; uses ALTER VIEW with the correct query. DROP VIEW product_summary; CREATE VIEW product_summary AS SELECT name, SUM(sales) FROM products GROUP BY name HAVING SUM(sales) > 500; drops and recreates the view, which is not needed. Options B and D use invalid commands.
  3. Final Answer:

    ALTER VIEW product_summary AS SELECT name, SUM(sales) FROM products GROUP BY name HAVING SUM(sales) > 500; -> Option B
  4. Quick Check:

    Use ALTER VIEW to update view query safely [OK]
Quick Trick: Use ALTER VIEW to update query without dropping [OK]
Common Mistakes:
MISTAKES
  • Dropping view unnecessarily before updating
  • Using UPDATE VIEW or REPLACE VIEW which are invalid
  • Not including HAVING clause in the new query

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes