Professional Documents
Culture Documents
A
The Sample Database
M
ost of the examples in this book are based on the sample database described in
this appendix. The sample database contains data that supports a simple order-
processing application for a small distribution company. It consists of five tables:
• PRODUCTS Contains one row for each type of product that is available for sale.
• OFFICES Contains one row for each of the company’s five sales offices where the
salespeople work.
• SALESREPS Contains one row for each of the company’s ten salespeople.
• CUSTOMERS Contains one row for each of the company’s customers.
• ORDERS Contains one row for each order placed by a customer. For simplicity,
each order is assumed to be for a single product.
Figure A-1 graphically shows the five tables, the columns that they contain, and the
parent/child relationships among them. The primary key of each table is shaded. The five
tables in the sample database can be created using the following CREATE TABLE and ALTER
statements.
Significant variations exist in the support for data types and syntax across available SQL
products. You will therefore find that the SQL statements shown here may require
modification to run on the SQL-based database that you are using. To help you sort out
those differences, scripts containing statements tailored for DB2, MySQL, Oracle, and SQL
Server are available for download from the McGraw-Hill web site. Scripts containing the
INSERT statements required to load sample data rows into the tables that match the
examples used throughout this book are also available. To access the downloads page,
follow these steps:
835
836 Part VII: Appendixes
5. Select the files you want, click them, and save them to your local computer system.
If the DBMS you are using is not shown, we suggest you start with the MySQL files,
because MySQL is the most compliant with the current SQL standard.
6. Consult the documentation for your DBMS and the SQL client you are using in
order to run the scripts in your database.
PART
NAME VARCHAR(15) NOT NULL,
PARTVIII
AGE INTEGER,
REP_OFFICE INTEGER,
TITLE VARCHAR(10),
HIRE_DATE DATE NOT NULL,
MANAGER INTEGER,
QUOTA DECIMAL(9,2),
SALES DECIMAL(9,2) NOT NULL,
PRIMARY KEY (EMPL_NUM),
FOREIGN KEY (MANAGER)
REFERENCES SALESREPS
ON DELETE SET NULL,
FOREIGN KEY WORKSIN (REP_OFFICE)
REFERENCES OFFICES
ON DELETE SET NULL);
Figures A-2 through A-6 show the contents of each of the five tables in the sample
database. The query results in examples throughout the book are based on the data shown
in these figures.
PART
11 New York Eastern 106 $575,000.00 $692,637.00
PARTVIII
12 Chicago Eastern 104 $800,000.00 $735,042.00
13 Atlanta Eastern 105 $350,000.00 $367,911.00
21 Los Angeles Western 108 $725,000.00 $835,915.00