Moreover,
two tables with a one-to-one relationship can be joined to form a single table.
One-to-Many Relationships
The one-to-many relationship happens when one record in a table can be associated with
multiple records in the related table but not vice versa. In our case, this happens for the
department-category relation. A specific department can contain any number of categories, but
each category belongs to exactly one department. Figure 5-2 better represents the one-to-many
relationship among departments and categories.
Another common scenario in which you see the one-to-many relationship is with the
order-order_detail tables, where order contains general details about the order (such as date,
total amount, and so on) and order_detail contains the products related to the order.
CHAPTER 5 ?– CREATING THE PRODUCT CATALOG: PART 2 115
Figure 5-2. A one-to-many relationship among departments and categories
The one-to-many relationship is implemented in the database by adding an extra column
in the table at the many side of the relationship, which references the ID column of the table
in the one side of the relationship. Simply said, in the category table, you??™ll have an extra column
(called department_id) that will hold the ID of the department the category belongs to.
You??™ll implement this in your database a bit later, after you learn about the many-to-many
relationships and foreign key constraints.
Pages:
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203