Skip to content
BENIBIX Learn

Database View

Development🗃️ DatabasesRelational Databases

Also known as SQL View, View

A saved query you can read from as if it were a table.

Think of it like

Think of it like a window that only shows part of a garden. The garden is the same, you just see less.

Example

Lucy's team keeps asking for this month's paid orders. She saves the query as a view called paid_orders, and everyone uses that.

Why it matters

Views let people use a hard query without writing it. They can also hide private columns.

Definition

A database view is a saved query that you can use as if it were a table. It stores no data of its own. Each time you read from it, the database runs the query behind it. Views hide hard joins behind a simple name, and they can show some columns while hiding others. You read from a view with SELECT, just like a table.

Example code

sql
CREATE VIEW rich AS
SELECT name FROM accounts WHERE balance > 60;
SELECT * FROM rich;
-- Emma
The view runs its saved query every time it is read.

Common mistake

Expecting a view to be fast because it looks like a table. It runs its whole query every time.

Key takeaways

  1. 1
    A saved query. It holds no data itself.
  2. 2
    Reads like a table. SELECT works the same way.
  3. 3
    Hides the hard part. Joins sit behind one name.

Compare