View vs materialized view
- SQL course
- Advanced
- Lesson 33/81
- 4 min
Compare the two view types.
View vs Materialized
A VIEW stores the query, a MATERIALIZED VIEW stores the result. The first is always fresh, the second is fast.
-- VIEW: her sorguda çalışır
-- MATERIALIZED VIEW: sonucu saklar, REFRESH gerekirView dynamic, mat view static.
View vs Materialized — details
A view is always fresh but may be slow. A materialized view is fast but may be stale.
If data must always be current (e.g. stock) use a regular view; if a delay of a few minutes is acceptable (e.g. a monthly revenue report) choose a materialized view.
Practice View vs Materialized
Create a VIEW and a MATERIALIZED VIEW; see the difference.
Starter code
-- create view
CREATE VIEWSample solution
CREATE VIEW v_summary AS
SELECT category, COUNT(*) FROM products GROUP BY category;Expected output
VIEW oluşturuldu
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Which is always fresh?
- VIEW Correct answer
- Both
- None
- MATERIALIZED VIEW
Explanation: A VIEW is always fresh.
2 VIEW
____ → stores the query, always current
VIEW → stores the query, always current
Explanation: A regular VIEW stores only the query and re-runs it every time, so it is always up to date.
3 View vs materialized view: match the terms
| Term | Meaning |
|---|---|
VIEW |
stores query |
MAT VIEW |
stores result |
fresh |
always |
fast |
mat view |