Dumies collection

Page 146

126

Part III: Storing and Retrieving Data Consider the VetLab database that I describe in Chapter 5. That database contains five tables: CLIENT, TESTS, EMPLOYEE, ORDERS, and RESULTS. Suppose the national marketing manager wants to see from which states the company’s orders are coming. Some of this information lies in the CLIENT table; some lies in the ORDERS table. Suppose the quality-control officer wants to compare the order date of a test to the date on which the final test result came in. This comparison requires some data from the ORDERS table and some from the RESULTS table. To satisfy needs such as these, you can create views that give you exactly the data you want in each case.

From tables For the marketing manager, you can create the view shown in Figure 6-1. CLIENT Table ClientName Address1 Address2 City State PostalCode Phone Fax ContactPerson

Figure 6-1: The ORDERS Table ORDERS_ BY_STATE OrderNumber ClientName view for the TestOrdered marketing Salesperson manager. OrderDate

ORDERS_BY_STATE View ClientName State OrderNumber

The following statement creates the marketing manager’s view: CREATE VIEW ORDERS_BY_STATE (ClientName, State, OrderNumber) AS SELECT CLIENT.ClientName, State, OrderNumber FROM CLIENT, ORDERS WHERE CLIENT.ClientName = ORDERS.ClientName ;


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.