Course contentsShow
← Databases & SQL
Lesson 52 of 1,9531. Relational FoundationsFree lesson

Views as Logical Abstractions

Create virtual tables that mask schema complexity or provide secure subsets of data.

In this lesson, you will learn how to use views to simplify complex database schemas and control data access.

What is a View?

Imagine you are working with a database containing dozens of tables joined together in complex ways. If you need to run the same complicated report every day, writing a long INNER JOIN query over and over is tedious and prone to errors. A View is essentially a "saved query" that acts like a virtual table. It doesn't store physical data itself; instead, it stores the logic of your query, allowing you to interact with it as if it were a standard table.

Simplifying Complexity

Views allow you to hide the "messy" parts of your database. If you have a Customers table, an Orders table, and an Order_Items table, you can create a view that presents a clean, flattened version of the data for your team:

CREATE VIEW CustomerOrderSummary AS
SELECT c.name, o.order_date, oi.product_name
FROM Customers c
JOIN Orders o ON c.id = o.customer_id
JOIN Order_Items oi ON o.id = oi.order_id;

Once this view is created, you can simply run SELECT * FROM CustomerOrderSummary;. You don't have to worry about the join syntax or table relationships—the database handles that logic for you behind the scenes.

Security through Abstraction

Views also act as a protective layer. If you have a sensitive table containing employee salaries, but you only want a manager to see names and departments, you can create a view that excludes the sensitive columns. By granting the manager access only to the view (and not the underlying base table), you ensure they can only see the data you have explicitly authorized.

In short, views turn your raw database schema into a streamlined, secure interface tailored to your specific needs, masking the underlying complexity while keeping your data integrity intact.

Key Takeaway: Views act as virtual tables that hide complex schema details and provide a secure, simplified way to access specific subsets of your data.