开发者

MySQL: Link tables

I have been creating my first database for a website and I have created the following diagram to work from. Does this look like it would work for many to many relationship between business and catego开发者_如何学编程ries as well as categories and subcategories?

Can you see any issues with it?

MySQL: Link tables


Looks ok, though the category_link_table can be problematic. Unless your business requirements allow for linking to a category OR a subcategory, then do not store both the main category and sub category IDs in the link table. Store only the the subcategory ID.

With both in there, you could potentially end up with categoryID/subcategoryIDs mismatches, where you've got something from a category 'A', and a subcategory 'p' in category 'B'.


A couple of comments:

  1. I don't see a need for the ID field in Link_table. business_id,catagory_id should be unique.

  2. Your Sub-category table setup seems odd, you have a link table. I'd have thought that each subcategory would simply have a field for the parent category (catagory_id). My preference for this kindn if thing is to have a catagory table with a parent_catagory_id and do self joins on the one table.


As a general point, I'd settle on naming conventions for your tables. I'd much prefer "business" to "business_data" - it reflects the business domain, rather than the technical concerns.

I'd also name your link tables differently - typically, "business_category" is cleaner, as is "category_subcategory".

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜