Prev | Current Page 194 | Next

Emilian Balanescu and Cristian Darie

"Beginning PHP and MySQL E-Commerce: From Novice to Professional, Second Edition"


By adding more records to the product_category table, you can associate a product with more
categories or a category with more products, effectively implementing the many-to-many
relationship.
Because the many-to-many relationship is implemented using a third table that makes the
connection between the linked tables, there is no need to add additional fields to the related
tables in the way that we added the department_id to the category table for implementing the
one-to-many relationship.
There??™s no definitive naming convention to use for the junction table. Most of the time it??™s
OK to just join the names of the two linked tables??”in this case, the junction table is named
product_category.
Enforcing Table Relationships Using Foreign Keys
Relationships among tables can be physically enforced in the database using FOREIGN KEY
constraints, or simply foreign keys.
You learned in the previous chapter about the PRIMARY KEY and UNIQUE constraints. We
covered them there, because they apply to the table as an individual entity. Foreign keys, on
the other hand, occur between two tables: the table in which the foreign key is defined (the
referencing table) and the table the foreign key references (the referenced table).
?– Tip Actually, the referencing table and the referenced table can be one and the same. This isn??™t seen too
often in practice, but it??™s not unusual either.


Pages:
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
parasole reklamowe meble do sypialni Leona Lewis Golec uOrkiestra 3 Firmy chińskie śląskie