0
0
MySQLquery~20 mins

Dropping and altering views in MySQL - 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 MySQL database with a view named employee_view. You run the command DROP VIEW employee_view;. What will be the result of trying to select from employee_view immediately after?
MySQL
DROP VIEW employee_view;
SELECT * FROM employee_view;
ASyntaxError due to invalid DROP VIEW syntax
BError: Table 'employee_view' doesn't exist
CThe original data from the underlying table is returned
DAn empty result set with zero rows
Attempts:
2 left
💡 Hint
Think about what happens to a view after it is dropped and if it still exists to be queried.
query_result
intermediate
2:00remaining
Altering a view with CREATE OR REPLACE
You have a view sales_summary defined as SELECT region, SUM(amount) AS total FROM sales GROUP BY region. You run the following command to change it:
CREATE OR REPLACE VIEW sales_summary AS SELECT region, COUNT(*) AS count FROM sales GROUP BY region;
What will be the output of SELECT * FROM sales_summary; after this change?
MySQL
CREATE OR REPLACE VIEW sales_summary AS SELECT region, COUNT(*) AS count FROM sales GROUP BY region;
SELECT * FROM sales_summary;
AA list of regions with the count of sales records per region
BSyntaxError because CREATE OR REPLACE is not supported in MySQL
CA list of regions with the total sales amount per region
DAn empty result set because the view was replaced with no data
Attempts:
2 left
💡 Hint
Consider what the new view definition selects and groups by.
📝 Syntax
advanced
2:00remaining
Identify the syntax error in dropping multiple views
Which of the following DROP VIEW statements is syntactically correct in MySQL to drop multiple views at once?
ADROP VIEW view1; view2; view3;
BDROP VIEW (view1, view2, view3);
CDROP VIEW view1, view2, view3;
DDROP VIEW view1; DROP VIEW view2; DROP VIEW view3;
Attempts:
2 left
💡 Hint
Check the syntax for dropping multiple views in one statement.
🔧 Debug
advanced
2:00remaining
Why does altering a view fail with an error?
You try to alter a view customer_data by running:
ALTER VIEW customer_data AS SELECT id, name FROM customers;
But MySQL returns an error. What is the reason?
MySQL
ALTER VIEW customer_data AS SELECT id, name FROM customers;
AThe view must be dropped before recreating it with a new definition
BALTER VIEW requires the keyword 'RENAME TO' to change the view name
CThe SELECT statement must include all columns from the original view
DMySQL does not support ALTER VIEW to change the SELECT statement
Attempts:
2 left
💡 Hint
Think about how MySQL handles changing view definitions.
🧠 Conceptual
expert
3:00remaining
Effect of dropping a view referenced by another view
Suppose you have two views:
CREATE VIEW view_a AS SELECT * FROM table_x;
CREATE VIEW view_b AS SELECT * FROM view_a WHERE col1 > 10;
If you run DROP VIEW view_a;, what happens when you try to query view_b?
MySQL
DROP VIEW view_a;
SELECT * FROM view_b;
AAn error occurs because view_b depends on the dropped view_a
Bview_b returns an empty result set
Cview_b returns data from table_x filtered by col1 > 10
Dview_b is automatically dropped when view_a is dropped
Attempts:
2 left
💡 Hint
Consider dependencies between views and what happens when a referenced view is removed.