Materialized Views

Unlike regular views, materialized views store the result of a query physically on disk. This allows for faster access to data since it does not need to be re-computed every time it is queried.

Creating a Materialized View:

CREATE MATERIALIZED VIEW mv_employee_salaries AS
SELECT department_id, AVG(salary) AS avg_salary
FROM employees
GROUP BY department_id;

Explanation: This creates a materialized view named mv_employee_salaries, which calculates and stores the average salary for each department. This is beneficial for performance in reporting scenarios.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *