Bird
0
0

You want to modify a view monthly_sales to add a new column showing sales tax calculated as 10% of sales. Which SQL command correctly applies this change?

hard📝 Application Q9 of 15
SQL - Views
You want to modify a view monthly_sales to add a new column showing sales tax calculated as 10% of sales. Which SQL command correctly applies this change?
ACREATE OR REPLACE VIEW monthly_sales AS SELECT sales, sales * 0.10 AS sales_tax FROM sales_data;
BALTER VIEW monthly_sales ADD COLUMN sales_tax AS sales * 0.10;
CUPDATE VIEW monthly_sales SET sales_tax = sales * 0.10;
DDROP VIEW monthly_sales; INSERT INTO monthly_sales SELECT sales, sales * 0.10 FROM sales_data;
Step-by-Step Solution
Solution:
  1. Step 1: Understand how to add columns in views

    Views are defined by SELECT queries; to add a column, redefine the view with a new SELECT including the calculated column.
  2. Step 2: Evaluate commands

    CREATE OR REPLACE VIEW monthly_sales AS SELECT sales, sales * 0.10 AS sales_tax FROM sales_data; uses CREATE OR REPLACE VIEW with a SELECT that adds sales_tax. Options A and C use invalid syntax. DROP VIEW monthly_sales; INSERT INTO monthly_sales SELECT sales, sales * 0.10 FROM sales_data; tries to insert into a view, which is not allowed.
  3. Final Answer:

    CREATE OR REPLACE VIEW monthly_sales AS SELECT sales, sales * 0.10 AS sales_tax FROM sales_data; -> Option A
  4. Quick Check:

    Redefine view with new SELECT to add columns = B [OK]
Quick Trick: Add columns by redefining view with new SELECT query [OK]
Common Mistakes:
MISTAKES
  • Trying to ALTER VIEW to add columns
  • Attempting to UPDATE view data
  • Inserting data into a view

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes