SQL · Queries that survive scale
What is a database view and when should you use one?
Short answer
A view is a named stored query that behaves like a table when queried. It does not store data by itself; it provides abstraction, reusable logic, and column-level access control.
A regular view expands to its defining query at execution time. It can simplify complex joins, present a stable interface to application code, and hide sensitive columns from some users.
CREATE VIEW active_customers AS
SELECT id, email, created_at
FROM customers
WHERE deleted_at IS NULL;
SELECT id, email
FROM active_customers
WHERE created_at >= '2026-01-01';What views are good for
- Encapsulating a recurring join or filter
- Exposing a stable API while underlying tables change
- Granting access to a subset of columns or rows
- Simplifying reporting queries for analysts
- Providing a compatibility layer during a schema migration
A view does not cache results, so a slow defining query is still slow when the view is queried. Some views are updatable, but complex joins, aggregates, and DISTINCT usually make them read-only. Check the engine rules before writing through a view.
Follow-ups you should expect
Interviewers use these to check whether the first answer was understanding or memorisation.
- 1Does a view store data on disk?
- 2When is a view updatable?
- 3How does a view differ from a materialized view?
- 4Can a view improve query performance?
Say it in the interview
A view is a named query that behaves like a table when selected from. It stores no data of its own, so it is mainly an abstraction and access-control tool. I use views to encapsulate recurring joins and expose a stable interface. They do not cache results, so performance still comes from the underlying query and indexes.
Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.
Related questions
Reading is step one
Now say it out loud.
Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live SQL mock interview and get scored feedback on depth, clarity and confidence.