MySQL + SQL · Lesson 94
Updatable Views in MySQL
Can a View Be Updated?
Some views are updatable — an INSERT/UPDATE on the view changes the base table. This works only for simple views (one table, no GROUP BY, no aggregate, no DISTINCT).
Example
CREATE VIEW active_students AS
SELECT roll_no, name, status FROM students WHERE status = 'active';
UPDATE active_students SET name = 'Aman K' WHERE roll_no = 1;
-- this updates the real students table
When a View is NOT Updatable
- Uses aggregate functions (SUM, COUNT...).
- Has GROUP BY or DISTINCT.
- Joins multiple tables in a complex way.
Summary
- Simple single-table views can be updated, changing the base table.
- Views with aggregates, GROUP BY or DISTINCT are read-only.