View Capabilities in Queries


Views are a very useful feature of relational systems. In most cases, views are used to control or direct access and for their ease-of-use characteristics. Relational views are like macros in other systems.

An often overlooked aspect of views is that they provide capabilities not available in normal SQL queries. Many useful queries can only be accomplished using views (examples are given below). Unfortunately, query formulators in larger shops are rarely authorized to create views.

View provide useful features not otherwise available in queries:

Views have disadvantages also: FirstSQL extends SQL to allow full queries (SELECT ... FROM ... WHERE ...) to be embedded in the FROM clause. This eliminates the disadvantages of views and provides many of the benefits. Embedded FROM queries can be renamed using a correlation name and the columns of the embedded query can be renamed.

A simple view definition:

CREATE VIEW namea (nameb, namec) AS
SELECT col1, col2 / col3
FROM   tab1 ;
could be referenced in a query as follows:
SELECT *
FROM   namea
WHERE  namec > 2 ;
This query can be expressed with an embedded FROM query as:
SELECT *
FROM   (SELECT col1, col2 / col3
        FROM   tab1
        AS     nameb, namec) namea
WHERE  namec > 2 ;
Some situations where embedded queries in the FROM clause are useful: The next section, General Use of Single Valued Subqueries, describes a FirstSQL extension that allows a subquery returning a single value to be used anywhere a scalar value can..

Return to Contents Page: Increase SQL Power?     Return to Can your Database do this?


Copyright © 1997 FFE Software, Inc. All Rights Reserved WorldWide