A view is a virtual table that shows data from one or more tables. It does not store data itself but displays data based on a query.
Click to reveal answer
beginner
How do you drop a view in MySQL?
Use the command DROP VIEW view_name; to remove a view from the database.
Click to reveal answer
intermediate
Can you alter a view directly in MySQL?
No, MySQL does not support direct alteration of views. Instead, you drop the view and recreate it with the new definition.
Click to reveal answer
intermediate
What is the correct way to change a view's query in MySQL?
First drop the existing view using DROP VIEW, then create a new view with the updated query using CREATE VIEW.
Click to reveal answer
beginner
What happens if you try to drop a view that does not exist?
MySQL will return an error unless you use DROP VIEW IF EXISTS view_name; which avoids errors if the view is missing.
Click to reveal answer
Which command removes a view named 'sales_view' in MySQL?
ADELETE VIEW sales_view;
BDROP VIEW sales_view;
CALTER VIEW sales_view;
DREMOVE VIEW sales_view;
✗ Incorrect
The correct command to remove a view is DROP VIEW followed by the view name.
How do you modify the query of an existing view in MySQL?
ADrop the view and recreate it with CREATE VIEW
BUse MODIFY VIEW command
CUpdate the view directly with UPDATE VIEW
DUse ALTER VIEW with new query
✗ Incorrect
MySQL requires dropping the view and recreating it to change its query.
What does the command DROP VIEW IF EXISTS view_name; do?
ACreates the view if it does not exist
BAlters the view if it exists
CDrops the view only if it exists, avoiding errors
DRenames the view if it exists
✗ Incorrect
This command safely drops a view only if it exists, preventing errors if it doesn't.
Which of the following is true about views?
AViews are virtual tables based on queries
BViews store data physically in the database
CViews cannot be dropped once created
DViews automatically update their structure
✗ Incorrect
Views are virtual tables that show data based on queries but do not store data themselves.
If you want to change a view's structure, what is the first step?
AUse ALTER VIEW command
BRename the view
CUpdate the underlying tables
DDrop the existing view
✗ Incorrect
Since MySQL does not support ALTER VIEW, you must drop the view first before recreating it.
Explain how to safely remove a view in MySQL and what happens if the view does not exist.
Think about how to prevent errors when dropping something that might not be there.
You got /3 concepts.
Describe the process to change the query of an existing view in MySQL.
Remember MySQL's limitation on altering views.
You got /3 concepts.
Practice
(1/5)
1. What does the DROP VIEW statement do in MySQL?
easy
A. Deletes an existing view from the database
B. Creates a new view in the database
C. Updates the data inside a view without deleting it
D. Renames an existing view
Solution
Step 1: Understand the purpose of DROP VIEW
The DROP VIEW command is used to remove a view completely from the database.
Step 2: Differentiate from other commands
Creating or updating views uses CREATE VIEW or ALTER VIEW, not DROP VIEW.
Final Answer:
Deletes an existing view from the database -> Option A
Quick Check:
DROP VIEW = delete view [OK]
Hint: DROP VIEW removes the view completely from the database [OK]
Common Mistakes:
Confusing DROP VIEW with ALTER VIEW
Thinking DROP VIEW updates data inside the view
Assuming DROP VIEW renames the view
2. Which of the following is the correct syntax to drop a view named employee_view?
easy
A. DELETE VIEW employee_view;
B. DROP employee_view;
C. DROP VIEW employee_view;
D. REMOVE VIEW employee_view;
Solution
Step 1: Recall the correct DROP VIEW syntax
The correct syntax to delete a view is DROP VIEW view_name;.
Step 2: Check each option
DROP VIEW employee_view; matches the correct syntax exactly. Others use invalid keywords like DELETE or REMOVE.
Final Answer:
DROP VIEW employee_view; -> Option C
Quick Check:
DROP VIEW + view name = correct syntax [OK]
Hint: Use DROP VIEW followed by the view name to delete it [OK]
Common Mistakes:
Omitting the VIEW keyword
Using DELETE or REMOVE instead of DROP
Adding extra semicolons inside the command
3. Given the view definition:
CREATE VIEW active_users AS SELECT id, name FROM users WHERE status = 'active';
What will be the result after running:
ALTER VIEW active_users AS SELECT id, name FROM users WHERE status = 'inactive';
and then querying SELECT * FROM active_users;?
medium
A. It will show users with status 'active'
B. It will cause a syntax error
C. It will show all users regardless of status
D. It will show users with status 'inactive'
Solution
Step 1: Understand ALTER VIEW effect
The ALTER VIEW statement changes the view's query to the new SELECT statement.
Step 2: Analyze the new query condition
The new view selects users where status = 'inactive', so querying the view returns inactive users.
Final Answer:
It will show users with status 'inactive' -> Option D
Quick Check:
ALTER VIEW changes query = shows inactive users [OK]
Hint: ALTER VIEW changes the view's query to the new SELECT statement [OK]
Common Mistakes:
Assuming ALTER VIEW appends to the old query
Expecting a syntax error from ALTER VIEW
Thinking the view still shows old data after alteration
4. You try to run the command:
ALTER VIEW sales_summary AS SELECT product_id, SUM(quantity) FROM sales GROUP BY product_id;
but get an error. What is the most likely cause?
medium
A. You cannot use GROUP BY in a view
B. The view sales_summary does not exist
C. ALTER VIEW requires DROP VIEW first
D. The view name is invalid
Solution
Step 1: Check prerequisites for ALTER VIEW
ALTER VIEW requires the specified view to already exist in the database.
Step 2: Rule out other causes
GROUP BY is allowed in views, no need to DROP first, and sales_summary is valid.
Final Answer:
The view sales_summary does not exist -> Option B
Quick Check:
ALTER VIEW requires existing view [OK]
Hint: Ensure the view exists before ALTER VIEW [OK]
Common Mistakes:
Thinking GROUP BY is not allowed in views
Trying to ALTER VIEW without dropping it first
Assuming view names cause this error
5. You have a view customer_orders that shows customer names and their order counts. You want to update it to also show the total order amount. Which sequence of commands correctly updates the view without losing it?
hard
A. ALTER VIEW customer_orders AS SELECT name, COUNT(*), SUM(amount) FROM orders GROUP BY name;
B. DROP VIEW customer_orders; CREATE VIEW customer_orders AS SELECT name, COUNT(*), SUM(amount) FROM orders GROUP BY name;
C. UPDATE VIEW customer_orders SET total_amount = SUM(amount);
D. MODIFY VIEW customer_orders AS SELECT name, COUNT(*), SUM(amount) FROM orders GROUP BY name;
Solution
Step 1: Identify how to update a view
Use ALTER VIEW to change the view's query without dropping it.
Step 2: Check the options
ALTER VIEW customer_orders AS SELECT name, COUNT(*), SUM(amount) FROM orders GROUP BY name; uses ALTER VIEW with the new SELECT statement including SUM(amount). DROP VIEW customer_orders; CREATE VIEW customer_orders AS SELECT name, COUNT(*), SUM(amount) FROM orders GROUP BY name; drops and recreates, which loses the view temporarily. The other options use invalid commands.
Final Answer:
ALTER VIEW customer_orders AS SELECT name, COUNT(*), SUM(amount) FROM orders GROUP BY name; -> Option A
Quick Check:
ALTER VIEW updates view query safely [OK]
Hint: Use ALTER VIEW to update view queries without dropping [OK]
Common Mistakes:
Dropping view unnecessarily before recreating
Using UPDATE or MODIFY which are invalid for views
Not including GROUP BY when using aggregation
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.