如果 Player 表中的大多数列表示目标或成就的状态,您可以考虑重复数据并将其建模在子表中。
Player Table
PlayerId (primary key)
PlayerName
Goals Table
GoalId (primary key)
GoalName
PlayerGoals Table
GoalId (primary key, foreign key to Goal)
PlayerId (primary key, foreign key to Player)
该Goals
表是一个主列表,您在编写游戏时设置一次。当玩家取得成就时,您将一行插入PlayerGoals
.
您应该根据预期的用例对数据进行建模。以这种方式建模(与多Players
列表相比)将使这些类型的查询更容易编写:-
- 列出球员以及他们完成了多少目标
- 哪个目标完成的玩家最多?
- 一般处理目标的任何其他查询
It would be easier to add a goal because it becomes a matter of inserting a row into the Goals
table rather than adding a column. However, maybe you need to write a bunch of code anyway and this is of no significance.
On the other hand, these types of queries will be easier if you have one big flat Player table with many columns:-
- Get me everything about a particular Player
- List every player that has completed Goal X
- List every player that has completed Goal X and not Goal Y
In the end, you need to choose if you want to make the concept of Goals
something that you model explicitly in the database or not. What is right and wrong depends on your priorities.