CSE Roadmap

Common tier · about 3 hours · 5 parts

Part 2 of 5 · 1 min read

A view as a stored query

What CREATE VIEW actually stores, and what querying it actually does.

Think of a saved search in an email client. The search itself is saved, not the list of matching emails. Running the saved search again re-runs the underlying search every time.

In plain words: CREATE VIEW stores a query's definition, not its result. Querying the view re-runs the stored query against the current data, every single time the view is queried. A view's result always reflects the underlying tables' current state, never a stale snapshot from when the view was created.

A worked example. A view listing only customers in Pune.

The key lines.

CREATE VIEW pune_customers AS
SELECT customer_id, full_name FROM customers WHERE address LIKE '%Pune%';

SELECT * FROM pune_customers;

View

A view is a stored query definition that behaves like a table when queried. Its result is computed fresh from the current data each time it is queried, not stored ahead of time.

Example: pune_customers stores the filtering logic, not a fixed list; a new customer added in Pune appears in the view immediately, with no extra step.