What’s the difference between materialized views and normal views in SQL?
Loading
What’s the difference between materialized views and normal views in SQL?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question.
Tuhin PaulPosted Feb 2, 2025, 4:44 AM
Part -2
SQL code that creates both a normal view and a materialized view for active policies
Tuhin PaulPosted Feb 2, 2025, 4:27 AM
Part - 1
Normal (Virtual) Views:
Definition:
A normal view is a virtual table that is defined by a SQL query. It does not store data physically; rather, it dynamically generates results when the view is queried.
Characteristics:
Materialized Views:
Definition:
A materialized view is similar to a normal view but stores the precomputed result set physically on disk. It is refreshed periodically or on-demand.
Characteristics:
Shubham SidnalePosted Feb 1, 2025, 4:50 PM
The key difference between materialized views and normal views in SQL lies in how they store and retrieve data:
1. Normal Views
CREATE VIEW EmployeeView AS
SELECT EmployeeID, Name, Department FROM Employees;
2. Materialized Views
CREATE MATERIALIZED VIEW SalesSummary AS
SELECT CategoryID, SUM(SalesAmount) AS TotalSales FROM Sales GROUP BY CategoryID;
REFRESH MATERIALIZED VIEW SalesSummary;
When to Use Which?
Feature
Normal View
Materialized View
Storage
No storage (virtual)
Stored physically
Data Freshness
Always up-to-date
Stale until refreshed
Performance
Slower for complex queries
Faster for read-heavy operations
Use Case
Frequently updated data
Precomputed aggregates, reporting
Muhammad Imran AnsariPosted Feb 1, 2025, 3:29 PM
Normal Views (Standard Views):
A normal view is a virtual table based on a SELECT query. It does not store data but dynamically retrieves it when queried. No physical storage, slower compared to materialized views and always shows up-to-date data from the base tables.
Materialized Views:
A materialized view stores the result of the query physically in the database. Requires disk space since it stores the computed data, faster for read-heavy workloads and needs to be refreshed (manually or automatically) to reflect changes in base tables.
Key Differences Summary: