What is a View?
Database Views
A View is a stored query definition that acts as a virtual table without storing data independently.
Creating and Using Views
-- Create a secure view that hides sensitive salary data
CREATE VIEW public_employees AS
SELECT id, name, department, city
FROM employees;
-- Query the view just like a real table
SELECT * FROM public_employees WHERE department = 'IT';
Key Advantages
- Security: Restricts access to sensitive rows and columns.
- Simplicity: Reusable abstraction over complex multi-table joins.
- Consistency: Centralizes business calculation logic.