0
0
SQLquery~20 mins

Dropping and altering views in SQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
View Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What happens after dropping a view?

Consider a view named employee_summary created on a table employees. After executing the command DROP VIEW employee_summary;, what will be the result of querying SELECT * FROM employee_summary;?

SQL
DROP VIEW employee_summary;
SELECT * FROM employee_summary;
AThe query raises an error because the view no longer exists.
BThe query returns an empty result set with the same columns as the view.
CThe query returns all rows from the original employees table.
DThe query returns the last cached result of the view before it was dropped.
Attempts:
2 left
💡 Hint

Think about what happens to a view after it is dropped and whether it still exists for querying.

📝 Syntax
intermediate
2:00remaining
Identify the correct syntax to alter a view

You want to change the definition of an existing view named customer_orders to include only orders from the last year. Which of the following SQL commands correctly updates the view?

ACREATE OR REPLACE VIEW customer_orders AS SELECT * FROM orders WHERE order_date >= CURRENT_DATE - INTERVAL '1 year';
BUPDATE VIEW customer_orders SET definition = 'SELECT * FROM orders WHERE order_date >= CURRENT_DATE - INTERVAL ''1 year''';
CALTER VIEW customer_orders AS SELECT * FROM orders WHERE order_date >= CURRENT_DATE - INTERVAL '1 year';
DMODIFY VIEW customer_orders AS SELECT * FROM orders WHERE order_date >= CURRENT_DATE - INTERVAL '1 year';
Attempts:
2 left
💡 Hint

Think about how to redefine a view without dropping it first.

🧠 Conceptual
advanced
2:00remaining
Effect of dropping a view on dependent objects

If a view sales_summary is dropped, which of the following statements about objects depending on this view is true?

AAll dependent views and stored procedures will automatically update to remove references to the dropped view.
BDropping the view will fail if there are dependent objects referencing it, unless those objects are dropped first.
CDependent objects will continue to work normally because they use cached data from the dropped view.
DDropping the view will cascade and automatically drop all dependent objects referencing it.
Attempts:
2 left
💡 Hint

Consider how databases handle dependencies when dropping objects.

🔧 Debug
advanced
2:00remaining
Why does this ALTER VIEW command fail?

Given the command below, why does it fail in most SQL databases?

ALTER VIEW product_list AS SELECT id, name FROM products WHERE active = TRUE;
SQL
ALTER VIEW product_list AS SELECT id, name FROM products WHERE active = TRUE;
AThe SELECT statement must include all columns from the base table.
BThe WHERE clause is not allowed in view definitions.
CThe view name must be enclosed in quotes to alter it.
DALTER VIEW does not support redefining the SELECT statement; CREATE OR REPLACE VIEW should be used instead.
Attempts:
2 left
💡 Hint

Think about the standard way to change a view's query.

optimization
expert
2:00remaining
Optimizing view updates with minimal downtime

You need to update a large view monthly_report used by many users. Dropping and recreating the view causes errors for users querying it during the update. Which approach minimizes downtime and errors?

ARename the old view, create a new view with the original name, then drop the old view after users switch.
BUse <code>DROP VIEW monthly_report;</code> then <code>CREATE VIEW monthly_report AS ...;</code> during off-hours only.
CUse <code>CREATE OR REPLACE VIEW monthly_report AS ...;</code> to atomically update the view definition without dropping it first.
DCreate a new view with a different name and ask users to switch manually to the new view.
Attempts:
2 left
💡 Hint

Consider atomic operations that do not remove the view before recreating it.