开发者

Should I reference a field id or have the actual data in the same row?

I have tw开发者_Go百科o tables, meetings_table and items_table.

items_table has three columns:

id
item
description

meetings_table has two columns:

first_party
second_party

I want to show the names of the two parties and the item they're meeting about. Should I add another column to meetings_table referencing the id of the item in items_table, then pull the item's name and description from there? Or should I add two columns to meetings_table, item and description and just run one query that way? Which is best in principal efficiency?


You should just reference the id of the item. This way, if you need to update anything about the item, you just do it in one location and it will propagate across all queries using that data. You almost never want to store data twice in a database. Every once in awhile you will come across a situation where unnormalized data is acceptable, but this is the exception, not the rule.


The best thing to do is to have an id for each item and add the id to the meetings_table, and query from there like

 SELECT * FROM meetings_table a, items_table b WHERE a.item_id=b.item_id

This will make item and meetings kinda independent of one another, and also saves space.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜