An updatable view is a virtual table that allows you to perform INSERT, UPDATE, or DELETE operations on it, and these changes affect the underlying base tables.
Click to reveal answer
intermediate
Which conditions must a view meet to be updatable in MySQL?
The view must select from a single table, not use GROUP BY, DISTINCT, or aggregate functions, and include all NOT NULL columns without default values from the base table.
Click to reveal answer
intermediate
Can you update a view that uses JOINs in MySQL?
No, views that use JOINs are generally not updatable because MySQL cannot determine how to apply changes to multiple base tables.
Click to reveal answer
beginner
What happens if you try to update a non-updatable view in MySQL?
MySQL will return an error saying the view is not updatable and will not allow the operation.
Click to reveal answer
advanced
How can you make a complex view updatable in MySQL?
You can create INSTEAD OF triggers to define how INSERT, UPDATE, or DELETE operations on the view affect the base tables, but MySQL does not support INSTEAD OF triggers, so you must use simpler views or handle updates in application logic.
Click to reveal answer
Which of the following views is updatable in MySQL?
AA view selecting from a single table without GROUP BY or DISTINCT
BA view using GROUP BY to aggregate data
CA view joining two tables
DA view using DISTINCT keyword
✗ Incorrect
Only views selecting from a single table without GROUP BY or DISTINCT are updatable in MySQL.
What happens if you try to update a view that uses JOINs in MySQL?
AThe update succeeds and changes all joined tables
BThe update is ignored silently
CThe update only affects the first table
DMySQL returns an error saying the view is not updatable
✗ Incorrect
MySQL does not allow updates on views with JOINs and returns an error.
Which SQL operation can you perform on an updatable view?
AUPDATE
BAll of the above
CDELETE
DINSERT
✗ Incorrect
Updatable views allow INSERT, UPDATE, and DELETE operations that affect the base table.
Why might a view not be updatable in MySQL?
AIt selects from a single table
BIt includes all NOT NULL columns
CIt uses aggregate functions like SUM or COUNT
DIt has no WHERE clause
✗ Incorrect
Views using aggregate functions are not updatable because the data is summarized.
Does MySQL support INSTEAD OF triggers to make complex views updatable?
ANo, MySQL does not support INSTEAD OF triggers
BYes, fully supported
COnly for DELETE operations
DOnly for INSERT operations
✗ Incorrect
MySQL does not support INSTEAD OF triggers, so complex views cannot be made updatable this way.
Explain what an updatable view is and list the main conditions that make a view updatable in MySQL.
Think about how changes in the view affect the base table.
You got /4 concepts.
Describe why views with JOINs are not updatable in MySQL and what alternatives exist to handle updates on complex views.
Consider how MySQL manages data changes behind the scenes.
You got /4 concepts.
Practice
(1/5)
1. What is an updatable view in MySQL?
easy
A. A view that only shows data but does not allow any changes.
B. A view that allows you to change the data in the underlying table through it.
C. A view that automatically creates new tables.
D. A view that stores data separately from the original table.
Solution
Step 1: Understand what a view is
A view is a saved query that shows data from one or more tables.
Step 2: Define updatable view
An updatable view lets you change data in the underlying table through the view itself.
Final Answer:
A view that allows you to change the data in the underlying table through it. -> Option B
Quick Check:
Updatable view = allows data change [OK]
Hint: Updatable views let you edit data through the view [OK]
Common Mistakes:
Thinking views store data separately
Confusing read-only views with updatable views
Assuming all views are updatable
2. Which of the following is the correct syntax to create an updatable view in MySQL?
easy
A. CREATE VIEW view_name UPDATEABLE AS SELECT * FROM table_name;
B. CREATE UPDATABLE VIEW view_name AS SELECT * FROM table_name;
C. CREATE VIEW view_name WITH UPDATE AS SELECT * FROM table_name;
D. CREATE VIEW view_name AS SELECT * FROM table_name;
Solution
Step 1: Recall MySQL view creation syntax
MySQL uses CREATE VIEW view_name AS SELECT ... to create views.
Step 2: Understand updatable views syntax
There is no special keyword for updatable views; they are updatable if the SELECT is simple enough.
Final Answer:
CREATE VIEW view_name AS SELECT * FROM table_name; -> Option D
Quick Check:
Standard CREATE VIEW syntax = CREATE VIEW view_name AS SELECT * FROM table_name; [OK]
Hint: No special keyword needed; simple CREATE VIEW works [OK]
Common Mistakes:
Adding non-existent keywords like UPDATABLE or WITH UPDATE
Using wrong syntax keywords
Assuming updatable views need special creation syntax
3. Given the table employees(id, name, salary) and the view: CREATE VIEW emp_view AS SELECT id, name FROM employees; Which of the following statements will succeed?
medium
A. UPDATE emp_view SET name = 'Alice' WHERE id = 1;
B. INSERT INTO emp_view (id, name) VALUES (4, 'Bob');
C. DELETE FROM emp_view WHERE salary = 2000;
D. UPDATE emp_view SET salary = 5000 WHERE id = 3;
Solution
Step 1: Check view columns and underlying table
The view selects only id and name, excluding salary.
Step 2: Determine which operations are allowed
Updating name through the view is allowed because it maps directly to the table column. INSERT fails (missing salary, assuming NOT NULL no default). DELETE referencing salary fails because salary not in view. Updating salary fails because salary not in view.
Final Answer:
UPDATE emp_view SET name = 'Alice' WHERE id = 1; -> Option A
Quick Check:
Update on view columns allowed = UPDATE emp_view SET name = 'Alice' WHERE id = 1; [OK]
Hint: You can update only columns included in the view [OK]
Common Mistakes:
Trying to update columns not in the view
Assuming inserts/deletes always work on views
Ignoring missing columns in the view
4. You created a view with: CREATE VIEW v AS SELECT id, name FROM employees WHERE salary > 3000; Why does the statement UPDATE v SET salary = 5000 WHERE id = 5; fail?
medium
A. Because the view does not include the salary column.
B. Because the view has a WHERE clause, making it non-updatable.
C. Because you cannot update views with more than one column.
D. Because the view name is invalid.
Solution
Step 1: Check the columns in the view and the UPDATE target
The view selects only id and name; salary is excluded.
Step 2: Check other options
A WHERE clause does not prevent updates to included columns. Views can have multiple columns and be updatable. The view name is valid.
Final Answer:
Because the view does not include the salary column. -> Option A
Quick Check:
Cannot update column not in view [OK]
Hint: Cannot modify columns absent from the view [OK]
Common Mistakes:
Thinking WHERE clause blocks updates
Assuming multiple columns prevent updates
Ignoring missing columns in the view
5. You want to create an updatable view on the orders table that shows only order_id and customer_id. You also want to allow updates to customer_id through the view. Which of the following is the best approach?
hard
A. CREATE VIEW order_view AS SELECT order_id FROM orders; Then update customer_id through order_view.
B. CREATE VIEW order_view AS SELECT order_id, customer_id FROM orders WHERE order_date > '2023-01-01'; Then update customer_id through order_view.
C. CREATE VIEW order_view AS SELECT order_id, customer_id FROM orders; Then update customer_id through order_view.
D. CREATE VIEW order_view AS SELECT order_id, customer_id, total FROM orders; Then update customer_id through order_view.
Solution
Step 1: Identify columns needed in the view
The view must include customer_id to allow updates on it.
Step 2: Avoid issues that limit updatability or scope
Adding a WHERE clause (as in B) limits updates to only recent orders. Including extra columns (as in C) shows more than requested. Excluding customer_id (as in A) prevents updating it. D provides exactly the requested columns without restrictions.
Final Answer:
CREATE VIEW order_view AS SELECT order_id, customer_id FROM orders; Then update customer_id through order_view. -> Option C
Quick Check:
Simple view with needed columns = updatable [OK]
Hint: Include columns to update, avoid WHERE filters [OK]
Common Mistakes:
Adding WHERE filters that limit updates
Excluding columns you want to update
Adding unnecessary columns that confuse
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.