Suppose i have a table with 3 fields
假设我有一个包含3个字段的表
Person_id, Name and address. Now the problem is that a person can have multiple addresses. and the principle of atomic values says that data should be atomic.
Person_id,姓名和地址。现在的问题是一个人可以拥有多个地址。原子价值原理说数据应该是原子的。
So then how am i suppose to store multiple addresses for a single person ?
那么我想如何为一个人存储多个地址?
3 个解决方案
#1
11
You're supposed to create an ADDRESS
table that has a foreign key linking it to a PERSON
record, i.e. PERSON_ID
. This is the "relational" component of a relational database, and it's why it's more flexible than a flat file (which is like a single table).
您应该创建一个ADDRESS表,该表具有将其链接到PERSON记录的外键,即PERSON_ID。这是关系数据库的“关系”组件,这就是它比平面文件(就像单个表)更灵活的原因。
#2
0
Put adresses in a second table, give each adress a "Person ID", so that mutiple rows in the adress-table can referr to on person.
将地址放在第二个表中,为每个地址指定一个“人员ID”,以便地址表中的多行可以引用到人。
#3
0
I would suggest adding a address type to the address table to identify which type of address it is (Home, Vacation, Office), etc. Something like: AddType that refers to a list table where more types could be added down the road.
我建议在地址表中添加一个地址类型,以确定它是哪种类型的地址(Home,Vacation,Office)等。类似于:AddType引用一个列表表,可以在路上添加更多类型。
#1
11
You're supposed to create an ADDRESS
table that has a foreign key linking it to a PERSON
record, i.e. PERSON_ID
. This is the "relational" component of a relational database, and it's why it's more flexible than a flat file (which is like a single table).
您应该创建一个ADDRESS表,该表具有将其链接到PERSON记录的外键,即PERSON_ID。这是关系数据库的“关系”组件,这就是它比平面文件(就像单个表)更灵活的原因。
#2
0
Put adresses in a second table, give each adress a "Person ID", so that mutiple rows in the adress-table can referr to on person.
将地址放在第二个表中,为每个地址指定一个“人员ID”,以便地址表中的多行可以引用到人。
#3
0
I would suggest adding a address type to the address table to identify which type of address it is (Home, Vacation, Office), etc. Something like: AddType that refers to a list table where more types could be added down the road.
我建议在地址表中添加一个地址类型,以确定它是哪种类型的地址(Home,Vacation,Office)等。类似于:AddType引用一个列表表,可以在路上添加更多类型。