In this tutorial, you’ll discover the fundamental differences between Views and Materialized Views, including how they handle data storage, retrieval, and performance. By the end, you’ll have a clear understanding of their advantages, limitations, and ideal use cases.
A logical, virtual table that is based on a query. It does not store any data itself; rather, it fetches the data from the base tables whenever it is queried.
A physical copy or snapshot of the result of a query. It stores the data on disk, independent of the base tables.
CREATE VIEW employee_view AS
SELECT id, name, department FROM employees WHERE status = 'active';
Fetches live data from the employees table every time employee_view is queried.
Materialized View Example
CREATE MATERIALIZED VIEW employee_mv
BUILD IMMEDIATE
REFRESH FAST ON DEMAND
AS
SELECT id, name, department, SUM(salary) AS total_salary
FROM employees
WHERE status = 'active'
GROUP BY id, name, department;
Stores the result of the query and can be refreshed on demand or at scheduled intervals.
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional
Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes.The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.