👁️ Views in SQL

Last Updated: January 2026


A View is a virtual table in SQL that stores a query result.

👉 It does not store data physically, but behaves like a table.

  • Simplify complex queries
  • Restrict user access to specific columns/rows
  • Reuse queries
  • Present aggregated or filtered data

Hinglish Tip 🗣: Agar aapko table ka customized version chahiye ya sensitive data hide karna ho, tab View use hota hai.


Basic CREATE VIEW Syntax

CREATE VIEW view_name AS
SELECT column1, column2, ...
FROM table_name
WHERE condition;

Example: Simple View

CREATE VIEW active_employees AS
SELECT emp_id, emp_name, salary
FROM employees
WHERE status = 'Active';
  • active_employees acts like a table
  • `Data is dynamic, updates with underlying table

Querying a View

SELECT * FROM active_employees;

📌 Fetches only active employees as defined in view


Updating Data Through Views

  • Some views allow INSERT/UPDATE/DELETE
  • Restrictions:
    • Cannot update computed columns
    • Cannot update aggregated data
    • DB-specific rules

⚠️ Important Points About Views

  • No physical storage (unless materialized)
  • Acts like a virtual table
  • Simplifies access control
  • Can be used in joins