Anda di halaman 1dari 13

One-to-One

Relationship
Considerations
One-to-One Relationship
Considerations
Simply include the primary key
of each table as a foreign key
in the other table
No guarantee that the
information will match

2
Figure 6-20
Rep

RepNum LastName FirstName CustomerNum


15 Campos Rafael 126
30 Gradey Megan 260
45 Tian Hui 334

Customer

CustomerNum CustomerName RepNum


126 Toys Galore 15
260 Brookings Direct 30
334 The Everything Shop 45

FIGURE 6-20: One-to-one relationship implemented by including the primary


key of one table as the foreign key (and alternate key) in the other
table
Figure 6-21
Rep

RepNum LastName FirstName CustomerNum


15 Campos Rafael 126
30 Gradey Megan 260
45 Tian Hui 334

Customer

CustomerNum CustomerName RepNum


126 Toys Galore 30
260 Brookings Direct 30
334 The Everything Shop 45

FIGURE 6-21: Implementation of one-to-one relationship in which information


does not match
One-to-One Relationship
Considerations

One solution: create a


single table
Workable, but not the best
solution

5
Figure 6-22
Customer

CustomerNum CustomerName RepNum LastName FirstName


126 Toys Galore 15 Campos Rafael
260 Brookings Direct 30 Gradey Megan
334 The Everything Shop 45 Tian Hui

FIGURE 6-22: One-to-one relationship implemented in a single table


6
One-to-One Relationship
Considerations

Better solution
Createseparate tables for
customers and sales reps
Include the primary key of
one of them as a foreign key
in the other

7
Figure 6-23, Solution 1
Rep

RepNum LastName FirstName CustomerNum


15 Campos Rafael 126
30 Gradey Megan 260
45 Tian Hui 334

Customer

CustomerNum CustomerName
126 Toys Galore
260 Brookings Direct
334 The Everything Shop

FIGURE 6-23: One-to-one relationship implemented by including the primary


key of one table as the foreign key (and alternate key) in the other
table
Figure 6-23, Solution 2
Rep

RepNum LastName FirstName


15 Campos Rafael
30 Gradey Megan
45 Tian Hui

Customer

CustomerNum CustomerName RepNum


126 Toys Galore 15
260 Brookings Direct 30
334 The Everything Shop 45

FIGURE 6-23: One-to-one relationship implemented by including the primary


key of one table as the foreign key (and alternate key) in the other
table
Many-to-Many Relationship
Considerations
Complex issues arise when more than two
entities are related in a many-to-many
relationship
Many-to-many-to-many relationship:
involves multiple entities
Deciding between a single many-to-many-
to-many relationship and two (or three)
many-to-many relationships
Crucial issue: independence

10
FIGURE 6-24
Sales

RepNum CustomerNum ItemNum


15 126 DL51
15 126 FD11
30 126 TR40
30 586 DL51
45 126 TR40
45 260 MT03
45 796 TR40

FIGURE 6-24: Sample sales data


Figure 6-25
RepCustomer ItemRep CustomerItem

RepNum CustomerNum RepNum ItemNum CustomerNum ItemNum


15 126 15 DL51 126 DL51
15 126 15 FD11 126 FD11
30 126 30 TR40 126 TR40
30 586 30 DL51 586 DL51
45 126 45 TR40 126 TR40
45 260 45 MT03 260 MT03
45 796 45 TR40 796 TR40

FIGURE 6-25: Results obtained by splitting the Sales table into three tables
Figure 6-26
Sales
RepNum CustomerNum ItemNum
15 126 DL51
15 126 FD11
30 126 DL51 !!!!
30 126 TR40
30 586 DL51
45 126 DL51 !!!!
45 126 DL51
45 260 MT03
45 796 TR40

FIGURE 6-24: Results obtained by joining three tables the third and sixth rows
are in error!

Anda mungkin juga menyukai