我如何标准化这个数据库设计?
我正在为客户创建一个赛艇报告和统计系统,目前我的结构类似于以下内容:
-----------------------------------------------------------------------------
| ID | Team | Coaches | Rowers | Event | Position | Time |
-----------------------------------------------------------------------------
| 18 | TeamName | CoachName1 | RowerName1 | EventName | 1 | 01:32:34 |
| | | CoachName2 | RowerName2 | | | |
| | | | RowerName3 | | | |
| | | | RowerName4 | | | |
-----------------------------------------------------------------------------
这是一个示例数据行,但我想将其扩展到 Rowers 表和 Coaches 表等但我不知道如何最好地将其链接回条目表,这就是这个表。
有人可以与我分享任何智慧之言吗?
更新
一个团队可以有任意数量的教练和赛艇运动员,一个赛艇运动员可以在多个团队(A、B、C 队等)中,一个团队可以有多个教练。
I am creating a rowing reporting and statistics system for a client where I have a structure at the moment similar to the following:
-----------------------------------------------------------------------------
| ID | Team | Coaches | Rowers | Event | Position | Time |
-----------------------------------------------------------------------------
| 18 | TeamName | CoachName1 | RowerName1 | EventName | 1 | 01:32:34 |
| | | CoachName2 | RowerName2 | | | |
| | | | RowerName3 | | | |
| | | | RowerName4 | | | |
-----------------------------------------------------------------------------
This is an example row of data but I would like to expand this out to a Rowers table and Coaches table and so on but I don't know how best to then link that back to the Entries table which is what this is.
Has anybody got any words of wisdom they could share with me?
Update
A Team can have any number of Coaches and Rowers, a Rower can be in many Teams (Team A, B, C etc) and a Team can have many Coaches.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我会为团队、教练、赛艇运动员(如果您想要扩展的运动类型不止一种)和赛事使用单独的表格。
团队
TeamID
教练
CoachID
赛艇运动员
RowerID
赛事
EventID
团队ID
RowerID
还有很多其他问题将进一步定义关系,例如:什么定义了条目(事件)? PER 项目是一组赛艇运动员和一名教练吗?每次比赛每组赛艇运动员有多名教练?有团队吗?团队由什么组成?
我会问这样的问题...
I would go with separate tables for Teams, Coaches, Rowers (maybe Athletes if there are more than one type of sport that you'll want to scale to) and Events.
Teams
TeamID
Coaches
CoachID
Rowers
RowerID
Events
EventID
TeamID
RowerID
There are a lot of other questions that will further define the relationships, like: What defines the entry (event)? Is it one set of rowers and one coach PER event? Multiple coaches per a set of rowers per event? Are there Teams? What makes up a team?
I'd be asking questions like that...
这是我的建议(基于最佳解决方案的答案):
团队
团队ID
团队名称
教练
教练ID
教练姓名
赛艇运动员
划船者ID
RowerName
活动
事件ID
职位
时间
: CoachTeamLink(
Coachs
和Teams
之间的链接)团队ID
CoachID
RowerTeamLink(
Rowers
和Teams
之间的链接)团队ID
RowerID
EventTeamLink(
Events
和Teams
之间的链接)团队ID
EventID
EventCoachLink(
Events
和Coachs
之间的链接)事件ID
CoachID
EventRowerLink(
Events
和Rowers
之间的链接)事件ID
划船者ID
This is my proposal (based on Optimal Solutions' answer):
Team
TeamID
TeamName
Coach
CoachID
CoachName
Rower
RowerID
RowerName
Event
EventID
Position
Time
CoachTeamLink (link between
Coachs
andTeams
)TeamID
CoachID
RowerTeamLink (link between
Rowers
andTeams
)TeamID
RowerID
EventTeamLink (link between
Events
andTeams
)TeamID
EventID
EventCoachLink (link between
Events
andCoachs
)EventID
CoachID
EventRowerLink (link between
Events
andRowers
)EventID
RowerID
您说您发布的内容是“条目表”,但该表没有多大意义,至少在(一行,没有双关语)=(一个事实或一件事)方面没有多大意义。
表中的行之一是 (NULL,NULL,NULL,RowerName3,NULL,NULL,NULL)。这意味着什么? CoachName2 教练的用途是什么?等等。
或者这可能是您的条目表的“一行”?如果是这样,则它不是一个好的 SQL 表,因为您在单个行列交叉点中有划船者列表(例如),并且“划船者列表”不是一个好的数据类型选择。
如果只看一些数据,就不可能说出如何规范化数据库。您需要知道数据在其建模的业务中意味着什么以及代表什么。
也就是说,在我看来,您至少需要单独的
团队 表
教练
赛艇运动员
事件
然后您需要表示业务场景的各个方面,例如“赛艇运动员属于一个团队”、“一个团队至少有一名教练,并且没有教练执教多个团队”。
我不知道条目是什么,但也许您也需要一个条目表。也许如果我了解划船就会更有意义。
You say what you posted is "the Entries table," but this table doesn't make much sense, and least not in terms of (one row, no pun intended) = (one fact or thing).
One of the rows in your table is (NULL,NULL,NULL,RowerName3,NULL,NULL,NULL). What does that mean? What is CoachName2 the coach for? And so on.
Or perhaps this is "one row" of your Entries table? If so, it's not a good SQL table, because you have lists of rowers (for example) in a single row-column intersection, and "list-of-rowers" isn't a good choice of data type.
It's impossible to say how to normalize a database if you only look at some data. You need to know what the data means and represents in the business it models.
That said, it looks to me like you at least need separate tables for
Teams
Coaches
Rowers
Events
And then you need to represent aspects of the business scenario like "A rower belongs to exactly one team," "A team has at least one coach, and no coach coaches more than one team."
I don't know what an Entry is from looking at this, but perhaps you need a table for Entries, too. Maybe if I knew about rowing it would make more sense.
我将有以下表格:
团队:ID、团队名称
教练:ID、教练姓名、团队ID
Rower: ID, RowerName, TeamID
然后您的事件表将填充如下:
事件:ID, TeamID, CoachID, RowerID, EventName, Position, Time
如果您想在查询中显示非规范化数据,您可以构建类似的内容:
I would have the following tables:
Team: ID, TeamName
Coach: ID, CoachName, TeamID
Rower: ID, RowerName, TeamID
Then your Event table would be populated as follows:
Event: ID, TeamID, CoachID, RowerID, EventName, Position, Time
If you wanted to display de-normalized data in a query, you would build something like:
我会尝试这样的事情::
I'd try something like this::