Database : what design to point on two possibilities?(数据库:关于两种可能性的设计要点是什么?)
问题描述
我正在为一个新项目设计一个数据模型.
其中一项要求指定某些对象可以指向个人或公司.
实现这一目标的最明智方法是什么?
我想过像这样的表格链接演员"(用优秀的
我建议你创建引用相同超类型(actor)的 company 和 person 子类型.请注意,您不需要单独的 person_id、company_id,因为参与者必须是一个或另一个,并且不能同时是两者.像这样:
I am designing a datamodel for a new project.
One of the requirements specifies that some objects can point either a person or a company.
What is the smartest way to achieve that?
I have thought about a table link "actor" like this (drawn with the excellent yUML.me BTW) :
In the actor
table, according to actor_type
, person_id
or company_id
is a foreign key on its corresponding table or is NULL
. This way, when one_table
wants to retrieve details about the actor
, I start by checking the actor_type
field and retrieve either person_id
or company_id
.
It is working, but I am looking for a better design. Here is the link for editing the diagram
I suggest you make company and person subtypes that reference the same supertype (actor). Note that you don't need separate person_id, company_id because an actor must be one or other and cannot be both. Like this:
这篇关于数据库:关于两种可能性的设计要点是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:数据库:关于两种可能性的设计要点是什么?


- 在SQL中,如何为每个组选择前2行 2021-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 更改自动增量起始编号? 2021-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- SQL 临时表问题 2022-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01