(Contents)(Previous)(Next)

Creating Views

A view has the effect of a window laid over an existing base table allowing parts of it to be seen, others to be hidden.

The following statement defines a view that includes all columns (cno, title, name, firstname, city, state, zip, and account), but only those rows that have a value greater than or equal to 0 in the column 'account'.

CREATE VIEW v1 AS

SELECT *

FROM customer

WHERE account >= 0

The statement

SELECT * FROM v1

produces:

Columns can be renamed and rearranged by using a view. Several tables can be joined. Each SELECT statement that does not contain ORDER BY can be used to define a view. A view name can be used in SELECT, INSERT, UPDATE, and DELETE statements. For an INSERT, columns missing in the view will be completed either by default values defined for this purpose or by the NULL value. But this cannot be done for every view; there are different restrictions.

A view has two purposes:

To reduce long SELECT statements.

To hide unimportant or confidential data.


(Contents)(Previous)(Next)