database-design - Is this a correct database design? (pk fk set and references)
问题描述
So parents can have many clubs and children. Each clubs can have many teams that have children in them. Children can join multiple teams.
I am confused with all these many relationships and I created a schema using a tool here: https://dbdiagram.io/d/5c455e3807ce540014df3eb2
Did I properly set keys and referenced them here?
解决方案
你的关系表设计看起来不错。作为替代方案,您可以考虑对父级和子级使用分层表。但是,这是设计考虑,完全取决于你(遵循 YAGNI(你不会弄坏它)原则)
Table person {
id int PK
name varchar
parent_id int
}
Table club {
id int PK
person_id int
class_id int
name varchar
}
Table team {
id int PK
club_id int
children_id int
num_of_children int
name varchar
}
Ref: person.id < club.person_id
Ref: club.id < team.club_id
Ref: team.children_id < person.id
Ref: person.parent_id > person.id
推荐阅读
- python - Django如何在创建新项目时添加默认变体
- python - Odoo:search_count 不显示存档记录
- selenium-webdriver - 第二次调用时无法识别 PageObjects
- javascript - 如何设置 Firebase 身份验证,只有具有自定义密码的用户才能注册?
- javascript - 暗模式 TypeError:无法将属性“onClick”设置为 null
- date - 如何使用 Moment.js 忽略时区?
- latex - 如何使用 \part* 重置章节计数器
- mysql - 为单个列获取多个值的搜索存储过程
- django - 如何将 base.html 用于默认 Wagtail Page 实例?
- python - 根据其他单元格值向单元格添加数据