【发布时间】:2013-06-25 07:33:53
【问题描述】:
我想设计我的项目的数据模型,但我在“客户”部分遇到了问题,因为我有两种类型的客户:自然人和法人实体 哪种方式最好:
方法一: 有 3 个这样的表:
Customers:
ID int not null (PK)
CustomerType bit not null
NaturalPersonID int (FK)
LegalPersonID int (FK)
NaturalPeople:
ID int not null (PK)
FirstName nvarchar(50) not null
LastName nvarchar(50) not null
NationalSecurityNumber char(10) not null
...
LegalEntities:
ID int not null (PK)
CompanyName nvarchar(100) not null
RegistrationNumber char(20) not null
...
填写 NaturalPersonID 或 LegalPersonID 中的一个,另一个为空,CustomerType 显示客户的类型(自然或法律)
方法二: 拥有一个包含所有字段的表:
ID int not null (PK)
CustomerType bit not null
FirstName nvarchar(50)
LastName nvarchar(50)
NationalSecurityNumber char(10)
CompanyName nvarchar(100)
RegistrationNumber char(20)
...
每个客户的某些字段已填写,其他字段为空
方法三: 要有一个包含一些字段的表:
ID int not null (PK)
CustomerType bit not null
FirstName nvarchar(50)
LastName nvarchar(100)
NationalSecurityNumber varchar(20)
...
为自然客户自然填充的字段。但如果客户是合法客户,我们会按逻辑放置数据。例如,LastName 字段中的 CompanyName 和 NationalSecurityNumber 字段中的 RegistrationCode 并且 FirstName 字段为空。
方法四: 我没有想到的任何其他方式,您可以提出建议
附:我正在 MS SQL Server 2012 中实现我的数据库
【问题讨论】:
-
看一下Party Data Model:tdan.com/view-articles/5014
-
你如何评价“最佳”?
标签: database-design