我怎样才能让一列存储任意数量的“用户”?
我有一个存储“匹配”的表,这些匹配具有以下列: MatchId, TeamA, TeamB, Wager,Winner
我希望能够使 TeamA 和 TeamB 返回每个球队的球员列表。每个数字可以是任意的,这可能吗?甚至实用吗?我想不出任何其他设计方法。对此是否有更好的模式?玩家将是 UserId 的,用户不绑定到团队,团队仅与比赛相关。
编辑: 例如, 玩家 A、B、C、D、E、F
第 1 场比赛:3v3 ABC vs DEF
Match2:3v3 DAB vs FEC
玩家不应绑定任何特定的 TeamId,因为它仅取决于比赛。玩家可以在比赛中与他或她想要的任何人组队。
I have a table that stores "Matches" these matches have the following columns:
MatchId, TeamA, TeamB, Wager,Winner
I want to be able to make TeamA and TeamB return a list of players for each team. The number could be arbitrary for each one, is this possible or even practical? I cant think of any other way of designing this. Is there a better schema over all for this? The players are going to be UserId's and a user is not bound to a team, the team is only relative to the match.
EDIT:
For instance,
Player A, B, C, D, E, F
Match 1: 3v3
ABC vs DEF
Match2: 3v3
DAB vs FEC
The player should not be bound to any specific TeamId because it is only dependant on the match. A player can team up with anyone he or she desires in a match.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
可能的数据库模式可能如下所示:
然后您可以像这样选择:
如果我的 SQL 边缘粗糙或模式是垃圾——它应该可能、可能、希望能勉强起作用。
该特定的 SQL 不会告诉您该球员所在的球队,但可以通过一些小的更改来获取该信息。
对于你想要的,与其他数据相关的数据,序列化不是答案 - 或者它不是你所想的......我感觉到术语不匹配。阅读有关使用 .NET 数据库的信息 - 网上有很多很棒的教程。还要阅读关系数据库设计,同样,网络资源对此非常有用。
A possible database schema could look like this:
You can then select out of it like so:
Excuse me if my SQL is rough around the edges or the schema is rubbish - it should likely, probably, hopefully, marginally work.
That particular SQL doesn't tell you the team the player was in, but the information is there to be had with some small changes.
For what you want, data that relates to other data, serialization is not the answer - or it's not what you think... I sense a terminology mismatch there. Read up on using databases from .NET - there are lots of great tutorials on the web. Also read up on relational database design, again web sources are great for this.
我假设您正在使用 .NET 来使用您的数据。
您可以创建一个团队类,其中包含 Players 属性作为列表。
在类上放置 [Serializable] 属性。
使用序列化方法将团队转换为字符串。
将字符串写入数据库。
使用反序列化方法将团队反序列化回内存对象。
请参阅这篇文章了解入门知识:http://msdn .microsoft.com/en-us/library/90c86ass(v=vs.71).aspx
就我个人而言,我会使用更多表格。拥有与玩家实体具有 1-* 关系的团队实体。将 Team FK 添加到您的比赛表中。
通过以下方式获取参加比赛的球员:
I am assuming you are using .NET to consume your data.
You can create a team class with a Players property as a List.
Place a [Serializable] attribute on the class.
Use a serialization method to convert the team to a string.
Write the string the the database.
Use a deserialzation method to deserailize the team back into the in memory object.
See this article for a primer: http://msdn.microsoft.com/en-us/library/90c86ass(v=vs.71).aspx
Personally I would use more tables. Have a Team entity with a 1-* relationship to a Player entity. Have the Team FK in your Matches table.
Get the players for a match by:
两种方法:
1:对 TeamA、TeamB 列使用 XML - 这样您就可以在易于在应用程序中处理的结构化字符串中创建完整的团队列表
2:使用更多表:更全面的架构可能是:(这是无意全面,甚至可能有些过分,但它说明了您可能想要如何思考)
匹配
匹配ID
姓名
发生的比赛
球队
团队ID
匹配ID
是主队
姓名
参加比赛的球队
玩家
玩家ID
团队ID
姓名
每个团队的所有球员
编辑:这是澄清要求后的更简单版本
Two approaches:
1: Use XML for the TeamA, TeamB columns - that way you can create the full team lists in a structured string thats easy to handle in your app
2: Use more tables: A more comprehensive schema might be: (This is not intended to be comprehensive and may even be over the top, but its an illustration about how you might want to be thinking)
Match
MatchID
Name
Matches that take place
Team
TeamID
MatchID
IsHomeTeam
Name
Teams that play in a match
Player
PlayerID
TeamID
Name
All players for each team
Edit: This is a simpler version after clarification of the requirements