Chapter 5. Linking Tables with Relationships
The tables youâve seen so far lead lonely, independent lives. You donât find this isolation with real-world databases. Real databases have their tables linked together in a web of relationships.
Suppose you set out to build a database that can manage the sales of your custom beadwork shop. The first ingredient is simple enoughâa Products table that lists your merchandiseâbut before long youâll need to pull together a lot more information. The wares in your Products table are sold in your Orders table. The goods in your Orders table are mailed out and recorded in a Shipments table. The people in your Customers table are billed in your Invoices table. All these tablesâProducts, Orders, Shipments, Customers, and Invoicesâhave bits of related information. As a result, if you want to find out the answer to a common question (like, âHow much does Jane Malone owe?â or âHow many beaded wigs did we sell last week?â), youâll need to consult several tables.
Based on what youâve learned so far, you already know enough to nail down the design for a database like this one. But relationships introduce the possibility of inconsistent information. And once a discrepancy creeps in, youâll never trust your database the same way again.
In this chapter, youâll learn how to explicitly define the relationships between tables. This process lets you prevent common errors, like data in different tables that doesnât sync up. It also ...
Get Access 2010: The Missing Manual now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.