Page 26 - AIS access_chang_ingraham
P. 26
24 CHAPTER 2 DATA MODELS AND RELATIONAL DATABASES
(1, N) (1, N)
Inventory Line Item ::--0001 Sales
FIGURE 2-4 Inventory-Sales Relationship
For example, for a grocery store, the relationship between the entities of "inventory"
and "sale" is often a many-to-many relationship, as indicated in Figure 2-4. That is, each
kind of inventory could be sold many times. And, the store may sell different kinds of
inventory in one transaction. If we include the attribute of "Item #" in the Sale Table as a
foreign key so that we know which items are sold, each sale record may have several values
for the attribute of "Item #," which violates the requirement that each attribute of a record
must be single-valued. A similar problem occurs when we try to use "Sale #" as a foreign
key in the Inventory Table. Therefore, we must create an additional table, a relationship
table, to link two tables with a many-to-many relationship. In Figure 2-4, the relationship
table is called the Line Item Table (in the diamond-shaped relationship symbol). This Line
Item Table is used to link the Inventory Table and the Sales Table. Recall that each sale
may include many kinds of inventory items. The primary keyS of this Line Item table is a
two-column attribute that includes both Sale # and Item # to make each record unique, and
to link the Inventory Table and the Sales Table. An example in Microsoft Access is shown
in Figure 2-5. The symbol of "00" in Access means many.
• All other attributes (columns) in a table must describe a characteristic of the entity
identified by the primary key. For example, including customer address or phone
number as an attribute in the Cash Receipt Table would be incorrect. To link to this
.=J.gJ~
Window tielp Type a question for help ... _ 0' x
-.
Imen ID
lternID IrwoiceDate
Caffeinated OrderDate
i-------l oo
Price Invoi:eID Cus1DrnerID
00
OnHand - Inven1I:rfID ErnployeeID
Quantity Cus1DrnerPO
Unitprice
Discount
Re;:lCiv NIJM
FIGURE 2-5 Inventory-S~lesRelationship Depicted in ACCESS
5 The primary key in a relationship table is always a combined key, composed of the primary keys from tables
in the relationshjp. This is called a concatenated primary key and may also be called a composite key.

