As databases mature, you package logic for reuse, consistency and security using views and stored procedures.
Views
A view is a saved query that behaves like a virtual table:
CREATE VIEW active_customers AS SELECT * FROM customers WHERE status = 'active';
Views simplify complex queries, present a consistent shape, and restrict access — users can read the view without touching the underlying tables.
Stored procedures
A stored procedure is saved, reusable SQL (with parameters and logic) that runs on the server:
- Encapsulates business logic in one place.
- Reduces round-trips and can improve performance.
- Limits direct table access — a security benefit.
Both support least privilege: grant access to the view/procedure, not the raw tables.
