【发布时间】:2021-11-10 23:20:04
【问题描述】:
我有两张桌子
recipe table
-----------------------
|recipe_id |name |
-----------------------
|1 |Pasta |
|2 |Pizza |
|3 |Fish |
ingredient table
-------------------------------
|ingredient_id |name |
-------------------------------
|1 |Spaghetti |
|2 |Salmon |
|3 |Tomato sauce|
我创建了一个名为“recipes_ingredients”的连接表
-------------------------------
|id |fk_recipe|fk_ingredient|
-------------------------------
|1 |1 |1 |
|2 |2 |3 |
|3 |3 |2 |
我的第一个问题是:我创建“recipes_ingredients”表的方式是否正确?我需要“id”还是只需要两个外键“fk_recipe”和“fk_ingredient”?
第二个是当我在其他两个表中插入记录时是否可以自动填充联结表。还是我必须手动添加联结表中的每个关联?
【问题讨论】:
-
请在每个帖子中只问 一个 问题,除非这几个问题非常非常接近。
-
@zupus 你有几个答案。如果答案对您有所帮助,您是否介意通过将答案标记为已接受来结束您的问题?这将有助于其他正在查看已接受答案的问题的人。
标签: sql postgresql junction-table