Views

Site Admin · 11 Sep 2026 · 2 views

A Saved Query You Can Query

A view is a SELECT with a name. It behaves like a table for SELECT purposes but does not store its own data.

CREATE VIEW active_customers AS
SELECT id, name, email FROM customers WHERE is_active = TRUE;

SELECT * FROM active_customers WHERE city = 'Mumbai';

Why Views Are Useful

  • Simplicity: hide complex joins behind a simple name.
  • Consistency: the same logic is used everywhere.
  • Security: expose only chosen columns; hide sensitive ones.
  • Stability: application code stays unchanged if the base tables change.

Managing Views

CREATE OR REPLACE VIEW active_customers AS ...
ALTER VIEW active_customers AS ...
DROP VIEW active_customers;

View vs Materialized View

A normal view runs its query every time it is read, so it is always fresh. A materialized view (PostgreSQL, Oracle) stores the result on disk and must be refreshed, but reads far faster.

Key Points

  • Views are named queries - virtual, not stored data.
  • They simplify, secure and stabilise application access.
  • Materialized views trade freshness for speed.
  • Use views for the joins and filters every report needs.
Share this post:

Comments (0)

Please login or register to comment.