Summary - Materialized view
- SQL course
- Advanced
- Lesson 35/81
- 5 min
Speed up a heavy report with a materialized view.
Summary - Materialized view
A materialized view physically stores the result. Created with CREATE, updated with REFRESH.
CREATE MATERIALIZED VIEW sales_summary AS
SELECT category, SUM(amount) FROM sales GROUP BY category;Summary mat view.
The materialized view sales_summary is created. category, SUM(amount) is selected from sales. Rows are grouped by category; aggregate functions are computed per group.
Practice Summary - Materialized view
Summary: create the sales_summary materialized view.
Starter code
-- summary mat view
CREATESample solution
CREATE MATERIALIZED VIEW sales_summary AS
SELECT category, SUM(amount) AS total
FROM sales GROUP BY category;Expected output
Materialized view oluşturuldu
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 What updates a materialized view?
- COMMIT
- ALTER
- REFRESH Correct answer
- DROP
Explanation: It is updated with REFRESH.
2 Summary - Materialized view: match the terms
| Term | Meaning |
|---|---|
materialized |
physical |
REFRESH |
update |
index |
speeds up |
view |
virtual |