简体   繁体   English

MySQL多对多关系表用法

[英]MySQL many-to-many relationship table usage

I have three tables: Resumes, Orgs, and Resume2Org. 我有三个表:Resumes,Orgs和Resume2Org。 Basically, Resume2Org is my many-to-many relationship table linking Resumes.resume_id to Orgs.org_id (so it only has those two keys in that table). 基本上,Resume2Org是我的多对多关系表,将Resumes.resume_id链接到Orgs.org_id(因此该表中只有这两个键)。

My question is, is it okay to use that many-to-many relationship table to store other data? 我的问题是,可以使用该多对多关系表存储其他数据吗? My use case: the database is part of a system to sift through incoming resumes. 我的用例:数据库是系统中筛选进入的简历的一部分。 But I've been asked to implement a "marked as read" feature so we can easily get the list of resumes we haven't looked at yet. 但有人要求我实现“标记为已读”功能,以便我们可以轻松获取尚未查看的简历列表。 But since a resume can belong to many different orgs, we only want to mark a resume as read for the org the user/viewer belongs to. 但是由于简历可以属于许多不同的组织,因此我们只希望将简历标记为用户/查看者所属组织的已读。 I thought, hey, having that flag in Resume2Org would be perfect. 我认为,嘿,在Resume2Org中具有该标志将是完美的。 Is this a smart approach, or should I create a new table specifically for "marked as read"? 这是一种聪明的方法,还是我应该专门为“标记为已读”创建一个新表? All the examples I've seen about many-to-many relationship tables is that those tables are used just for that... linking two tables. 我看到的关于多对多关系表的所有示例都是这些表仅用于...链接两个表。

Yes it is okey to have additional fields in a many-to-many table. 是的,在多对多表中包含其他字段是可以的。 I think it is the right way to do in your case as you don't need to join additional tables and you save spaces. 我认为这是正确的处理方式,因为您无需联接其他表,从而节省了空间。

I was in a very similar situation last week and I added additional field for that. 上周我的情况非常相似,为此我添加了其他字段。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM