Updatable VIEWs
- SQL course
- Intermediate
- Lesson 75/115
- 4 min
Insert, update and delete through some views.
Updatable VIEW
Simple VIEWs allow INSERT, UPDATE and DELETE through them.
UPDATE active_customers SET status = 'vip' WHERE id = 1;This query updates customer status through the VIEW.
In active_customers, status = 'vip' is updated. Only the rows where id = 1 holds are affected.
Updatable VIEW — details
Updatable VIEWs must be simple: no JOIN, GROUP BY or DISTINCT.
For example, in a single-table view like active_customers, UPDATE … SET status = 'vip' updates the customers table directly.
Practice Updatable VIEW
Set status to 'vip' for id=1 through the active_customers VIEW.
Starter code
-- update view
UPDATE active_customersSample solution
UPDATE active_customers SET status = 'vip' WHERE id = 1;Expected output
1 satır güncellendi
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Add UPDATE
____ active_customers SET status = 'vip' WHERE id = 1;
UPDATE active_customers SET status = 'vip' WHERE id = 1;
Explanation: Simple single-table views can be updated with UPDATE; the change is written to the underlying table.
2 Updatable VIEWs: match the terms
| Term | Meaning |
|---|---|
UPDATE |
update |
VIEW |
virtual |
simple |
updatable |
JOIN |
forbidden |
3 Which VIEWs are updatable?
- Ones with GROUP BY
- Simple ones Correct answer
- Ones with JOIN
- Everyone
Explanation: Simple VIEWs are updatable.