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.
💻 Live Code Editor
Is page ki language (MYSQL) mein code likhein aur turant chalाएं — yahीं, bina kuch install kiye.Powered by OneCompiler. Agar editor na khule to yahान naye tab mein kholein.
💻 Live Code Editor
Is page ke program yahan ready hain — chalाएं, badlें aur seekhें. Bina kuch install kiye.
Powered by OneCompiler. Editor mein code apne aap aa jata hai — Run dabaakर output dekhें.
Agar load na ho to naye tab mein kholें.