我如何标准化这个数据库设计?

发布于 2024-08-02 06:52:49 字数 887 浏览 11 评论 0原文

我正在为客户创建一个赛艇报告和统计系统,目前我的结构类似于以下内容:

-----------------------------------------------------------------------------
| 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 技术交流群。

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

发布评论

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

评论(5

熟人话多 2024-08-09 06:52:49

我会为团队、教练、赛艇运动员(如果您想要扩展的运动类型不止一种)和赛事使用单独的表格。

团队

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...

初心未许 2024-08-09 06:52:49

某种链接表?那么我如何将多个赛艇运动员和教练映射到一个团队?

这是我的建议(基于最佳解决方案的答案):

团队
团队ID
团队名称

教练
教练ID
教练姓名

赛艇运动员
划船者ID
RowerName

活动
事件ID
职位
时间

  1. 如果您想要预定义团队,请花

CoachTeamLinkCoachsTeams 之间的链接)
团队ID
CoachID

RowerTeamLinkRowersTeams 之间的链接)
团队ID
RowerID

EventTeamLinkEventsTeams 之间的链接)
团队ID
EventID

  1. 或者,如果您没有:

EventCoachLinkEventsCoachs 之间的链接)
事件ID
CoachID

EventRowerLinkEventsRowers 之间的链接)
事件ID
划船者ID

A sort of link table? How would I then map multiple Rowers and Coaches to one Team?

This is my proposal (based on Optimal Solutions' answer):

Team
TeamID
TeamName

Coach
CoachID
CoachName

Rower
RowerID
RowerName

Event
EventID
Position
Time

  1. if you want predefined teams:

CoachTeamLink (link between Coachs and Teams)
TeamID
CoachID

RowerTeamLink (link between Rowers and Teams)
TeamID
RowerID

EventTeamLink (link between Events and Teams)
TeamID
EventID

  1. Or if you dont:

EventCoachLink (link between Events and Coachs)
EventID
CoachID

EventRowerLink (link between Events and Rowers)
EventID
RowerID

め七分饶幸 2024-08-09 06:52:49

您说您发布的内容是“条目表”,但该表没有多大意义,至少在(一行,没有双关语)=(一个事实或一件事)方面没有多大意义。

表中的行之一是 (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.

歌枕肩 2024-08-09 06:52:49

我将有以下表格:

团队:ID、团队名称
教练:ID、教练姓名、团队ID
Rower: ID, RowerName, TeamID

然后您的事件表将填充如下:

事件:ID, TeamID, CoachID, RowerID, EventName, Position, Time

如果您想在查询中显示非规范化数据,您可以构建类似的内容:

SELECT E.ID, T.TeamName, C.CoachName, R.RowerName, E.EventName, E.Position, E.Time
FROM Event E
INNER JOIN Team T
ON E.TeamID = T.ID
INNER JOIN Coach C
ON E.CoachID = C.ID
INNER JOIN Rower R
ON E.RowerID = R.ID

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:

SELECT E.ID, T.TeamName, C.CoachName, R.RowerName, E.EventName, E.Position, E.Time
FROM Event E
INNER JOIN Team T
ON E.TeamID = T.ID
INNER JOIN Coach C
ON E.CoachID = C.ID
INNER JOIN Rower R
ON E.RowerID = R.ID
你不是我要的菜∠ 2024-08-09 06:52:49

我会尝试这样的事情::

teams
  id
  name


rowers
  id
  name
  team_id REFERENCES TEAMS (id)

coaches
  id
  name
  team_id REFERENCES teams (id)

events
  id
  name
  starting_time
  length

event_teams
  event_id references events (id)
  team_id references teams (id)
  position

I'd try something like this::

teams
  id
  name


rowers
  id
  name
  team_id REFERENCES TEAMS (id)

coaches
  id
  name
  team_id REFERENCES teams (id)

events
  id
  name
  starting_time
  length

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