需要有关标准化下表的最佳方法的建议:
以前,我有一张桌子:
personId year dob column1 column2 column3
-------- ---- --- ------- ------- -------
这里,(personId+year
)是主键,dob
,column1
,column2
和column3
列具有唯一值。
现在,根据新的要求column1
,column2
和column3
将存储多个值。从非常幼稚的意义上讲,它应该具有以下值:]
personId year dob column1 column2 column3
-------- ---- ------ ------- ------- -------
1 2018 2.1.20 A1, A2 B1 C1, C2, C3
我只是不想将其规范化为First Normal Form,但想将其分解为更多表,例如:
表1:
personId year dob
-------- ---- ------
1 2018 2.1.20
表2:
personId year column1
-------- ---- ------
1 2018 A1
1 2018 A2
表3:
personId year column2
-------- ---- ------
1 2018 B1
表4:
personId year column3
-------- ---- ------
1 2018 C1
1 2018 C2
1 2018 C3
现在表1在我看来还不错,因为它的PK仍为(personId
+ year
),但是表2-3看起来很优雅,因为它们缺少主键。
是否有更好的方法来实现这一目标?
您很近。您应该为第一个表引入一个新的主键,我也将为其他表推荐主键:
表1:
t1Id personId year dob
1 1 2018 2.1.20
表2:
t2Id t1Id column1
1 1 A1
2 1 A2
表3:
t3Id t1id column2
1 1 B1
表4:
t4Id t1id column3
1 1 C1
2 1 C2
3 1 C3
如果排序很重要,您可能还希望在除第一个表之外的所有表中包括一个顺序编号列。
此外,最后三个表中的数据列可能是其各自表的ID。