Database Reference
In-Depth Information
customers that has just names and phone numbers. The following SQL statement defines a
view, BasicCustomerDataView, which will produce that list:
/* *** SQL-CREATE-VIEW-CH07-02 *** */
CREATE VIEW CustomerBasicDataView AS
SELECT LastName AS CustomerLastName,
FirstName AS CustomerFirstName,
AreaCode, PhoneNumber
FROM
CUSTOMER;
To use this view, we can run the SQL statement:
/* *** SQL-Query-View-CH07-02 *** */
SELECT
*
FROM
CustomerBasicDataView
ORDER BY
CustomerLastName, CustomerFirstName;
The result is:
If the management of the View Ridge Gallery wants to hide the columns AcquisitionPrice
and SalesPrice in TRANS, they can define a view that does not include those columns. One use
for such a view is to populate a Web page.
SQL views also can hide rows by providing a WHERE clause in the view definition. The
next SQL statement defines a view of customer name and phone data for all customers with
an address in Washington State:
/* *** SQL-CREATE-VIEW-CH07-03 *** */
CREATE VIEW CustomerBasicDataWAView AS
SELECT LastName AS CustomerLastName,
FirstName AS CustomerFirstName,
AreaCode, PhoneNumber
FROM CUSTOMER
WHERE State='WA';
To use this view, we can run the SQL statement:
/* *** SQL-Query-View-CH07-03 *** */
SELECT
*
FROM
CustomerBasicDataWAView
ORDER BY
CustomerLastName, CustomerFirstName;
Search WWH ::




Custom Search