Database Views

A View is a mechanism that provides a way for DBMS to hide certain data from different users.

Some reasons may include:

Untitled

A View is simply another relation that is defined on top of the existing stored (base) tables.

There are two types of views.

  1. Virtual Views: Not stored, generated each time the relation is accessed.
  2. Materialized Views: Constructed and stored; updated periodically depending on the query definition.

SQL Syntax

Declared by:

CREATE [MATERIALIZED] VIEW <name> as <query>;

Note: The default view is virtual.

Example:

CREATE VIEW CanDrink AS
			SELECT drinker, beer
			FROM Frequent, Sells
			WHERE Frequent.bar = Sells.bar;

This query creates a virtual view containing the drinker-beer pairs which reflects what bar a drinker goes to which serves a type of beer.

Updating Views