Types of Views


Types of Views:-

  1. Simple Views
  2. Complex Views 
  3. Materialized Views
# Simple Views:-
A Simple View is a basic, read-only abstraction of data , ideal for simplifying access to specific columns or rows. It derives data from a single table.
Example:- CREATE VIEW EmployeeNames AS
                   SELECT EmployeeID, FirstName, LastName
                   FROM Employees;

# Complex Views:-
A Complex View integrates multiple tables and advanced SQL logic, perfect for combining and deriving meaningful insights. It utilizes JOINs, GROUP BY, and other SQL constructs. and can include functions, subqueries, and aggregations.
Example:- CREATE VIEW EmployeeSales AS
                   SELECT e.EmployeeID, e.FirstName, e.LastName, SUM(s.SalesAmount) AS TotalSales
                   FROM Employees e
                   JOIN Sales s ON e.EmployeeID = s.EmployeeID
                   GROUP BY e.EmployeeID, e.FirstName, e.LastName;

# Materialized Views in SQL:-
A Materialized View (also known as a snapshot) is a database object that contains the results of a query and physically stores the data. Unlike regular views, which fetch data dynamically when queried, materialized views store the query output, allowing for faster query execution by avoiding repetitive computation.
Materialized Views in SQL Server:-
Materialized Views are not directly supported s they are in databases like Oracle or PostgreSQL. However, similar functionality can be achieved using Indexed Views. Indexed Views store the results of a view physically on disk, similar to a materialized view.

Talk to us?

Post your blog