SQL views and updatability:\nEvaluate the claim:\n\n"A view that contains a computed (derived) column can be easily updated."

Difficulty: Easy

Correct Answer: Incorrect

Explanation:


Introduction / Context:
This question tests your understanding of SQL view updatability, particularly when a view includes a computed (derived) column such as a concatenation, arithmetic expression, or CASE expression. While views are powerful for abstraction and security, not all views are inherently updatable, and derived columns introduce special constraints that frequently block direct updates.


Given Data / Assumptions:

  • The view includes at least one computed expression (for example, price * quantity as total_amount).
  • No special INSTEAD OF triggers or rules are defined to handle updates.
  • We consider mainstream relational DBMS behavior (e.g., SQL Server, Oracle, PostgreSQL, MySQL) with default settings.


Concept / Approach:
A view is updatable only if the DBMS can map INSERT/UPDATE/DELETE on the view unambiguously to corresponding operations on the underlying base table rows and columns. Computed columns do not exist as stored attributes; they are generated from other columns at query time. Therefore, attempting to update a computed value is either meaningless or ambiguous unless the DBMS has rules to reverse the computation or a trigger that translates the update to base columns.


Step-by-Step Solution:

Identify the computed column: e.g., total = unit_price * qty.Ask whether updating total directly tells the DBMS how to update unit_price or qty. It does not.Without extra logic (INSTEAD OF trigger), the DBMS will reject the update or mark the view as non-updatable for that column.Conclusion: The claim that such a view can be "easily" updated is false in general.


Verification / Alternative check:
Some DBMSs allow updates to non-computed columns of the view provided the rest of the updatability rules are met (key preservation, no aggregates, no DISTINCT, etc.). But the computed column itself remains non-updatable unless handled by triggers/rules.


Why Other Options Are Wrong:

  • Correct: Overstates capability; computed expressions are not directly writable.
  • Valid only if the DBMS...: Even with advanced engines, direct updates to computed fields still require mapping logic.
  • Applies only when all base tables have triggers: Triggers can help, but they do not make the general statement true.
  • Insufficient information: The presence of a computed column is enough to reject the blanket claim.


Common Pitfalls:
Assuming that because a column displays in a view it can be updated; forgetting key-preserved table rules; confusing computed columns with persisted generated columns (which still are not directly user-writable in many systems).


Final Answer:
Incorrect

More Questions from SQL for Database Construction

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion