13.09.2016 Views

PHP and MySQL Web Development 4th Ed-tqw-_darksiderg

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

210 Chapter 8 Designing Your <strong>Web</strong> Database<br />

CUSTOMERS<br />

CustomerID<br />

Name<br />

Address<br />

City<br />

1<br />

Julie Smith<br />

25 Oak Street<br />

Airport West<br />

2<br />

Alan Wong<br />

1/47 Haines Avenue<br />

Box Hill<br />

3<br />

Michelle Arthur<br />

357 North Road<br />

Yarraville<br />

ORDERS<br />

OrderID<br />

CustomerID<br />

Amount<br />

Date<br />

1<br />

3<br />

27.50<br />

02-Apr--2007<br />

2<br />

1<br />

12.99<br />

15-Apr-2007<br />

3<br />

2<br />

74.00<br />

19-Apr-2007<br />

4<br />

3<br />

6.99<br />

01-May-2007<br />

Figure 8.2<br />

Each order in the Orders table refers to a customer from the<br />

Customers table.<br />

The relational database term for this relationship is foreign key. CustomerID is the primary<br />

key in Customers, but when it appears in another table, such as Orders, it is referred to<br />

as a foreign key.<br />

You might wonder why we chose to have two separate tables.Why not just store<br />

Julie’s address in the Orders table? We explore this issue in more detail in the next<br />

section.<br />

Schemas<br />

The complete set of table designs for a database is called the database schema. It is akin to<br />

a blueprint for the database. A schema should show the tables along with their columns,<br />

<strong>and</strong> the primary key of each table <strong>and</strong> any foreign keys. A schema does not include any<br />

data, but you might want to show sample data with your schema to explain what it is<br />

for.The schema can be shown in informal diagrams as we have done, in entity relationship<br />

diagrams (which are not covered in this book), or in a text form, such as<br />

Customers(CustomerID, Name, Address, City)<br />

Orders(OrderID, CustomerID, Amount, Date)<br />

Underlined terms in the schema are primary keys in the relation in which they are<br />

underlined. Italic terms are foreign keys in the relation in which they appear italic.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!