开发者

Should I still use many-to-many db structure if I only have a few-to-many?

I'm new to web development and could really use some advice. Thank you all in advance!

I have a form where I ask users to rate their experience in several areas (Mental, Physical, Fun) from 1 - 10. There are about 10 areas in all. Is it worth it to make a table of areas and a intersection table with areaID and userID? In this case, wouldn't it be easier to just create 开发者_运维知识库one table with 11 columns (one for each area plus a userID)?

I understand that a table of 'areas' with a key of areaID would be the most robust, and allow me to later add more areas but I really don't see myself doing that. Also, as I only expect <1000 users, would adding another column to a MySQL db be a lot of work?

Finally, what is the cutoff point where I actually should use a many-to-many structure? Later in the form I have users rate ~30 fields from 1 - 4. Should I use the two table system there?

Thanks again!


It'd be better to use the separate child table. The SQL overhead for a join is minimal, and you get total flexibility in how many/few entries you want to allow, without ever having to change the database structure.

It may only be 10 areas now, but PHBs are notorious for changing their minds about something that was "bedrock" on the hour before launch.


I would always model a many-to-many relationship with a proper intersection table because you can never predict what the future will bring.


Suppose you want to count the number of areas per user. How would you do that if you use a single table with 11 columns?

Implement this with the intersection table. You will be glad you did.


Both makes sense, but I would choose the many-to-many approach as you can then specify in the areas table the name of each area (and maybe add some comments what 1 or 10 for that specific area means, etc..)


There's no wrong answer to this, but consider this: are you sure that that number will remain fixed at ten?

Personally, I would still use the many-to-many relationship. It's the more elegant solution, and, in my mind, better. However, doing a job well is often a waste of time.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜