MySQL:链接表

发布于 2024-11-18 21:37:47 字数 191 浏览 2 评论 0原文

我一直在为网站创建第一个数据库,并创建了下图以供使用。这看起来适用于业务和类别以及类别和子类别之间的多对多关系吗?

你能看出它有什么问题吗?

我的数据库

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 categories as well as categories and subcategories?

Can you see any issues with it?

My Database

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

谈场末日恋爱 2024-11-25 21:37:47

看起来不错,尽管category_link_table 可能有问题。除非您的业务要求允许链接到类别或子类别,否则不要在链接表中同时存储主类别和子类别 ID。仅存储子类别 ID。

如果两者都存在,您可能会遇到类别 ID/子类别 ID 不匹配的情况,即您从类别“A”中获得某些内容,而在类别“B”中获得子类别“p”。

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'.

何止钟意 2024-11-25 21:37:47

几点评论:

  1. 我认为 Link_table 中不需要 ID 字段。 business_id,catagory_id 应该是唯一的。

  2. 您的子类别表设置似乎很奇怪,您有一个链接表。我原以为每个子类别都会有一个父类别的字段(catagory_id)。我更喜欢这种类型,如果有一个带有parent_catagory_id 的目录表,并在一个表上进行自连接。

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.

伪装你 2024-11-25 21:37:47

一般来说,我会确定表的命名约定。与“business_data”相比,我更喜欢“business”——它反映了业务领域,而不是技术问题。

我还会以不同的方式命名您的链接表 - 通常,“business_category”更清晰,“category_subcategory”也是如此。

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".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文