Database Reference
In-Depth Information
Figure 19.1
CREATE VIEW
Syntax Is Fairly
Simple.
19.3.1
Creating Simple Views
A simple view is the easiest type of view to create.
CREATE VIEW USARTISTS AS
SELECT ARTIST_ID, NAME, CITY, STATE_PROVINCE, ZIP
FROM ARTIST WHERE COUNTRY = 'USA';
The view we have just created can be queried as if it were a table. When
you execute a query on a view, the entire query contained within the view
definition is executed to retrieve the columns and rows of the subquery,
Then your query is applied to the view and the final results are displayed.
Query the view by executing these format commands and query. Figure
19.2 shows the result.
COLUMN NAME FORMAT A20
COLUMN CITY FORMAT A15
COLUMN STATE_PROVINCE FORMAT A10
SELECT * FROM USARTISTS;
You can use a view in a join as if it were another table. For example, you
can list all U.S. artist names and their song titles with this query:
SELECT NAME, TITLE FROM USARTISTS NATURAL JOIN SONG
ORDER BY 1,2;
Search WWH ::




Custom Search