数据库:什么设计指出两种可能性? [英] Database : what design to point on two possibilities?

查看:101
本文介绍了数据库:什么设计指出两种可能性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设计一个新项目的数据模型。



其中一个要求规定某些对象可以指向某人或公司。



最聪明的方法是什么?



我已经考虑过一个表链接 这样(用优秀的

解决方案

我建议您制作公司和个人子类型引用相同的超类型(actor)。请注意,您不需要单独的person_id,company_id,因为actor必须是一个或其他,不能同时使用。像这样:




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:

这篇关于数据库:什么设计指出两种可能性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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