我有以下问题:
我正在开发一个具有以下实体的应用程序: “人”,“个人”,“公司”,“客户”,“供应商”
“人”实体是一种抽象。 “个人”是“人”,但“公司”也是“人”,但有一些不同的属性。
我的问题是:“客户”可能是“个人”,也可能是“公司”,如何将其存储在数据库中?
tbl_individual
id
person_id
Data_1
Data_2
...
data_N
tbl_company
id
person_id
Data_1
Data_2
...
data_N
tbl_customer
id
individual_id // Only completed when the client is "Individuals"
company_id // Only completed when the client is "Enterprise"
Data_1
Data_2
...
data_N
tbl_person // Here placed the data of "Individuals" and "Company"
id
Data_1
Data_2
...
data_N
tbl_customer
id
person_id
Data_1
Data_2
...
data_N
答案 0 :(得分:0)
选项2似乎很好。只需为type
和附加表tbl_person
添加列tbl_company_data
:
tbl_person // Here placed the data of "Individuals" and "Company"
id
type [1 - individual, 2 - company]
Data_1
Data_2
...
data_N
tbl_customer
id
person_id
Data_1
Data_2
...
data_N
tbl_company_data
id
person_id
Data_1
Data_2
...
data_N