Q46: When is a SQL View updatable directly via DML statements?
A view can accept direct INSERT, UPDATE, or DELETE statements only if the underlying query meets strict criteria:
- The view references exactly one base table in its
FROMclause. - The query contains no aggregation clauses (
GROUP BY,HAVING,SUM,AVG,COUNT). - The query contains no set operations (
UNION,INTERSECT,EXCEPT) orDISTINCTclauses. - All target non-null columns missing from the view definition must have default values.
Key Takeaways
- Views are updatable only when mapped cleanly to a single underlying base table.
- Aggregations, set operations, and DISTINCT clauses prevent direct DML modifications on views.