Concept Flow - Updatable views
Create View
Query View
Update View Data?
Update Base Table
Reflect Changes in View
This flow shows how an update on a view is checked and either applied to the base table or rejected if not allowed.
CREATE VIEW v_emp AS SELECT id, name, salary FROM employees; UPDATE v_emp SET salary = salary + 100 WHERE id = 2;
| Step | Action | Evaluation | Result |
|---|---|---|---|
| 1 | Create view v_emp | View created on employees(id, name, salary) | View v_emp ready |
| 2 | Update v_emp set salary = salary + 100 where id = 2 | Check if view is updatable | View is updatable |
| 3 | Translate update to base table | Update employees set salary = salary + 100 where id = 2 | Base table updated |
| 4 | Reflect changes in view | Query view for id=2 | Salary increased by 100 |
| 5 | End | No more updates | Update complete |
| Variable | Start | After Step 3 | Final |
|---|---|---|---|
| salary (id=2) | 5000 | 5100 | 5100 |
CREATE VIEW view_name AS SELECT columns FROM table; Updates on simple views affect the base table directly. Only views without joins, aggregates, or complex expressions are updatable. Updating a view translates to updating the underlying table. If not updatable, update commands on the view fail.
updatable view in MySQL?CREATE VIEW view_name AS SELECT ... to create views.employees(id, name, salary) and the view:CREATE VIEW emp_view AS SELECT id, name FROM employees;id and name, excluding salary.name through the view is allowed because it maps directly to the table column.salary, assuming NOT NULL no default).salary fails because salary not in view.salary fails because salary not in view.CREATE VIEW v AS SELECT id, name FROM employees WHERE salary > 3000;UPDATE v SET salary = 5000 WHERE id = 5; fail?id and name; salary is excluded.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?customer_id to allow updates on it.customer_id (as in A) prevents updating it.Pass the test and this pattern moves unknown