In SQL, what is the purpose of the CREATE VIEW statement, and when would a developer use it over querying base tables directly?

Difficulty: Easy

Correct Answer: to define a view of one or more tables or views

Explanation:


Introduction / Context:
Views are saved query definitions that present data from one or more base tables (or other views) as a virtual table. They are crucial for abstraction, security, reuse, and simplifying complex joins or filters for application use.


Given Data / Assumptions:

  • We are using standard SQL semantics.
  • CREATE VIEW defines a named, reusable query.
  • Views do not store independent row copies by default; they reference base data.


Concept / Approach:
The command CREATE VIEW establishes a virtual table whose result set derives from a SELECT statement. Developers use views to encapsulate business logic, expose only necessary columns, enforce row-level filtering, and stabilize application interfaces even when base schemas evolve. Views can also aid permission systems by granting access to a view while restricting base tables.


Step-by-Step Solution:

Identify what CREATE VIEW does: defines a virtual table via SELECT.Relate to use cases: abstraction, security, simplified querying.Choose the option that describes definition over one or more tables or views.


Verification / Alternative check:
DBMS documentation consistently defines views as named queries; recompilation and triggers are separate features (e.g., ALTER VIEW, CREATE TRIGGER).


Why Other Options Are Wrong:

  • Recompile view/table: handled by other mechanisms.
  • Create a trigger: different DDL command.
  • None of the above: incorrect because CREATE VIEW is for defining views.


Common Pitfalls:
Assuming views always materialize data; unless explicitly materialized, a view is virtual and derives rows on demand.


Final Answer:
to define a view of one or more tables or views

Discussion & Comments

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