用于保存数组的 SQL 结构?
如何将一个表与另一个表中的多条记录关联起来?
基本上,我有一个“事件”表,如何跟踪哪些“用户”(在他们自己的单独表中)处于特定事件中?现在,我在“事件”表中只有一列,其中包含已加入该“事件”的用户 ID 的逗号分隔列表。
一定有更好的方法来做到这一点......对吧?
How can I relate a table with multiple records from another table?
Basically, I have a table for an 'event', how do I keep track of which 'users' (in their own seperate table) are in a particular event? Right now I just have a column in the 'event' table with a comma separated list of the users IDs who have joined that 'event'.
There must be a better way to do this...right?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通常,您有一个名为
users_in_event
的表,该表为与events
表建立多对多关系的每个用户保存一行。因此,对于每个事件,您将有许多表行单独映射到用户。要找出哪些用户参与了活动,请执行以下操作:
Typically you have a table called
users_in_event
which holds one row for each user in a many-to-many relationship with theevents
table. So for each event, you will have a number of table rows mapped individually to users.To find out which users are in an event, do:
如果您具有多对多关系,即用户可以参加许多事件,并且事件可以由许多用户参加,那么传统上会用映射表来表示,该映射表具有每个表的主键以及任何特定的属性用户与事件的关系。
例如,如果
USER
和EVENT
表中的 ID 列均为INT
类型:If you have a many-to-many relationship, that is, users can attend many events, and events can be attended by many users, that would traditionally be represented with a mapping table with the primary key from each table, plus any attributes specific to the user-event relationship.
For example, if you have ID columns in your
USER
andEVENT
tables that are both typeINT
: