Difficulty: Easy
Correct Answer: Both of the above
Explanation:
Introduction / Context:Views can encapsulate business rules and computed values, providing a stable interface while underlying tables evolve. This reduces duplication and prevents errors.
Given Data / Assumptions:
Concept / Approach:By placing expressions (e.g., price * quantity, tax calculations, standardized CASE logic) in a view, developers avoid rewriting them in every report or query. Centralization ensures consistent behavior and simplifies maintenance if the business rule changes—update the view once and all consumers benefit.
Step-by-Step Solution:
Identify repeated expression → move it into the view’s SELECT list as a derived column.Grant permissions on the view to expose the computed result while hiding raw columns if needed.Consumers select from the view, gaining both convenience and consistency.Verification / Alternative check:Compare codebases before/after: fewer duplicated expressions, reduced defect surface area, and simpler queries.
Why Other Options Are Wrong:Only one of the benefits: Ignores the other equally important advantage. Cannot appear in a view / storage size: Views are virtual; computations in the SELECT are fully supported and do not directly change physical storage.
Common Pitfalls:Complex computations in views can impact performance if not indexed properly (consider indexed/materialized views where supported and appropriate).
Final Answer:Both of the above
Discussion & Comments