Part 111: Introduction to Views: Virtual Tables & Security
A View is a saved, named SQL query that behaves like a virtual table. It does not store physical data itself; it queries the underlying tables dynamically whenever invoked.
1. Syntax
CREATE OR REPLACE VIEW active_customers AS
SELECT id, name, email, country, created_at
FROM customers
WHERE is_active = TRUE;
2. Security Benefit: Restricting Sensitive Columns
Grant junior developers or external analysts access to the view rather than the underlying table:
-- Exclude password_hash and ssn from the view!
CREATE VIEW public_employee_directory AS
SELECT id, first_name, last_name, email, department
FROM employees;
Key Takeaways
- Views simplify complex queries and restrict access to sensitive columns.
In Part 112, we explore Updatable Views & The WITH CHECK OPTION!

