我想写一个应用程序来计算纸牌游戏中的积分。以下是游戏的运作方式:
这是我对应用程序数据库的设计:
- MatchID: primary key, integer
- Date:
- Player1: player name, varchar
- Player2: varchar
- Player3: varchar
- Player4: ..
- Player5: ..
- Player6: ..
- Player7: ..
- Player8: ..
- MID: foreign key reference to MATCH.MatchID
- GameID: the ID of each game in a match, integer
- PID: should reference to Player 1-8
- Points: integer
POINTS表的示例(4名玩家):
| MID | GameID | PID |积分|
| 1 | 1 | 1 | 5 |
| 1 | 1 | 2 | 3 |
| 1 | 1 | 3 | 0 |
| 1 | 1 | 4 | 2 |
| 1 | 2 | 1 | 0 |
| 1 | 2 | 2 | 10 |
| 1 | 2 | 3 | 20 |
| 1 | 2 | 4 | 30 |
...
我的问题是:
如何在MATCH表中将POINTS.PID引用到播放器1-8?我在考虑将PID的数量与列名称Player#相匹配,但它听起来并不像是一个合适的解决方案。
有没有更好的方法来设计这个数据库?
如果对玩家数量没有限制,我该如何设计这个数据库?
提前谢谢!
答案 0 :(得分:1)
除非玩家数量较少(如2)并且您确定它一直都是固定的,否则您可能不希望将玩家表示为MATCH表中的列。相反,你应该有一个单独的MATCH_PLAYERS表来指示比赛中的球员:
MATCH table:(MatchID, MatchDate)
MATCH_PLAYERS table:(MatchID, PlayerID, PlayerName)
其中{MatchID,PlayerID}是MATCH_PLAYERS表的主键。
这应该可以解答您的大多数问题/解答。