一对一运动的数据库设计 [英] Database Design for one-on-one sports

查看:96
本文介绍了一对一运动的数据库设计的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我正在开发一个跟踪拳击结果的应用程序。是跟踪这两个表的最佳方法,如下所示:

  Boxers 
====
id
名称

匹配
=======
id
match_number
boxer_id
opponent_id
结果

...然后每个匹配有两个记录,一个为赢家,一个为失败者,这样的东西:

  id match_number boxer_id opponent_id result 
- ---- -------- -------- ----------- ------
1 1 1001 2001 WIN
2 1 2001 1001 LOSS

...或者我错过了更好的方法吗?



如果没有结果存储,只是两个对手匹配的录音呢?



谢谢! >

解决方案

嗯,为了完全正常化,我会去:



拳击手 - 引用。



比赛:

  id / match_number不要以为这些需要变得清晰了)
的赢家(FK-Boxers;

对手:

  id(无意义的PK值。可选。
您可以使用其他两个字段作为PK)
match_id
boxer_id

反对者中有两行,每场比赛有一行。



(更新以从其他答案中添加建议)


Let's say that I'm developing an application to track boxing results. Is the best way to track these to have two tables, like so:

Boxers
======
id
name

Matches
=======
id
match_number
boxer_id
opponent_id
result

... and then have two records for each match, one for the winner, and one for the loser, something like this:

id match_number boxer_id opponent_id result
-- ------------ -------- ----------- ------
1  1            1001     2001        WIN
2  1            2001     1001        LOSS

... or am I missing a better way to do this?

What if there wasn't a result stored, just a recording that the two opponents were matched up?

Thanks!

解决方案

Well, for a fully normalized, I'd go with:

Boxers - as cited.

Matches:

id  / match_number   (Don't think these need to be distinct anymore)
winner (FK-Boxers; Nullable, for for matches scheduled, but not decided yet)

Opponents:

id  (meaningless PK value.  Optional. 
     you could use the other two fields as the PK)
match_id
boxer_id

Two rows in Opponents and one in Matches for each match.

(Updated to add suggestions from other answers)

这篇关于一对一运动的数据库设计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆