MySQL:需要架构帮助 - 如何处理列表?

发布于 2024-10-13 08:15:53 字数 525 浏览 2 评论 0原文

我有一个用于输入足球运动员信息的表格,其中有一个字段可以输入该球员效力过的所有球队。我们的想法是,这些球员的记录将用于生成球队索引和个人球队页面。然后,球队页面将显示在某个时刻曾经加入过球队的所有球员的记录。

这就是它抽象的运作方式。我不太确定如何处理这个领域;我正在考虑在用户输入团队时用逗号分隔它们。然而,我更关心如何在数据库本身中处理后端。

如果每个玩家有多个与他关联的团队,我应该如何在玩家的数据库表中存储 团队 属性? 目前,因为该表单是关于单个玩家的,我正在使用的主表是 players 表。该表的每一行都是关于一个球员及其统计数据,包括他曾效力过的球队列表的属性。我想我可能需要一个额外的团队表。这个辅助表上的每一行不会包含太多内容,只是一个 ID,然后是一个玩家列表。但是,我该如何处理该球员名单呢?

对于如何处理这种情况有什么建议吗?有更好的解决方案吗?

I have a form for inputting information about a football player, with a field to enter in all of the teams that the player has been on. The idea is that records of these players will be used to generate an index of teams, and individual team pages. The team pages would then display records of all players who have once been on the team at some point.

That's how it works in abstract. I'm not exactly sure how to handle the field; I'm thinking of having the teams be comma separated when the user inputs them. However, I'm more concerned about how to handle the backend, in the database itself.

If each player has multiple teams associated with him, how should I store the teams attribute in the db table for players? At the moment, since the form is about a single player, the main table I'm working with is the players table. Each row of this table is about a single player and his stats, including an attribute that is a list of teams he has been on. I think I may need an additional table for teams. Each row on this secondary table wouldn't consist of much, just an id, and then a list of players. But then, how would I then handle that list of players?

Any suggestions as to how to deal with this situation? Is there a better solution?

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

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

发布评论

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

评论(1

玩世 2024-10-20 08:15:53

您正在描述多对多关系。您需要一个“player”表、一个“team”表和一个“player_team”关联表。 assoc 表将同时具有player_id 和team_id。然后,您可以通过在 assoc 表上执行联接来加载与给定团队关联的玩家。

You are describing a many-to-many relationship. You need a "player" table, a "team" table, and a "player_team" assoc table. The assoc table would have both a player_id and a team_id. You can then load players associated with a given team by doing a join on the assoc table.

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