many to many relationship

前端 未结 2 1401
被撕碎了的回忆
被撕碎了的回忆 2021-01-06 05:02

If I have two tables - table beer and table distributor, each one have a primary key and a third table that have the foreign keys and calls beer_

2条回答
  •  天涯浪人
    2021-01-06 05:26

    You've definitely got the right idea. Your beer_distributor table is what's known as a junction table. JOINs and keys/indexes are used together. The database system uses keys to make JOINs work quickly and efficiently. You use this junction table by JOINing both beer and distributor tables to it.

    And, your junction table should have a primary key that spans both columns (a multiple-column index / "composite index"), which it looks like it does if I understand that diagram correctly. In that case, it looks good to me. Nicely done.

提交回复
热议问题