Skip to content
uencoder

View

A view is a stored query definition (a virtual table) holding no data, computed dynamically at query time, used to simplify queries, isolate security, and abstract.

Purpose

To provide query abstraction and data security isolation, simplifying reuse of complex queries.

Mechanism

CREATE VIEW name AS SELECT... The view stores the query definition, not data, and expands into a subquery at query time. Column/row access can be restricted (security). Materialized views physically store results and refresh periodically, suited to heavy computation.

Use cases

  • Encapsulating and reusing complex queries
  • Column/row-level permission isolation
  • Data abstraction and compatibility
  • Report precomputation (materialized views)

Examples

  • Input
    CREATE VIEW active_users AS SELECT * WHERE active
    Output
    Virtual table

    Computed dynamically

Common errors

Deeply nested complex views perform poorly
Use materialized views or optimize the underlying query

Related terms

References