创建一个数据库表,其中的条目可以来自另一个表或全新的输入 [英] Create a database table where entries can come from another table or entirely new input

查看:83
本文介绍了创建一个数据库表,其中的条目可以来自另一个表或全新的输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张客户,员工和供应商表。他们每个人都有一些常用字段,例如姓名,地址,contact_no和电子邮件以及其他字段。现在,我想要一个称为投资者的新表格。但是,投资者可以来自员工,供应商,客户或全新的人。投资者也具有上述共同领域以及自己的领域。我该如何设计表格?

I have a table of customers, employees, and suppliers. Each of them has some common fields like name, address, contact_no, and email along with other fields. Now, I want a new table called investors. However, investors can be from employees, suppliers, customers, or entirely new people. Investors also have the aforementioned common fields as well as their own fields. How do I go about designing the table?

推荐答案

如何拥有一个通用表 people 包含公共字段(名称,地址等),并 JOIN 适当的特定表?

How about having a generic table people that would contain the common fields (name, address, etc.) and JOIN the appropriate specific table?

要读取客户(按客户ID),您将选择*来自其他人p加入客户c在p.id = c.person_id上c.id = ...

To read a customer (by customer ID) you would SELECT * FROM people p JOIN customers c ON p.id = c.person_id WHERE c.id=...

要读取投资者(按投资者ID),您可以选择*从人p加入投资者i ON p.id = i.person_id在哪里i.id = ...

To read an investor (by investor ID) you would SELECT * FROM people p JOIN investors i ON p.id = i.person_id WHERE i.id=...

这样,同一个人既可以是客户又可以是投资者,这仅取决于观点

This way the same person can be a customer and an investor, it just depends on the point of view.

这篇关于创建一个数据库表,其中的条目可以来自另一个表或全新的输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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