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 activeOutputVirtual tableComputed dynamically
Common errors
- Deeply nested complex views perform poorly
- Use materialized views or optimize the underlying query
Related terms
Stored Procedure
A stored procedure is a precompiled SQL program stored in the database that can be invoked on demand, reducing network round trips and SQL-injection risk. GLOSSARY
JOIN
JOIN is the SQL operation combining rows of multiple tables by a join condition; types include inner, left/right/full outer, and cross joins. GLOSSARY
Index
An index is an auxiliary data structure (e.g., B+ tree, hash) maintained to speed up queries, trading space for time at the cost of write overhead. GLOSSARY