oracle 为数据库中的单个字段存储多个值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10572987/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Storing multiple values for a single field in a database
提问by Some Body
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 ?
那么我该如何为一个人存储多个地址呢?
回答by Marc
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
. 这是关系数据库的“关系”组件,这就是它比平面文件(就像单个表)更灵活的原因。
回答by Jim H
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”,以便地址表中的多行可以引用个人。
回答by Steven Lee
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.
我建议在地址表中添加一个地址类型,以确定它是哪种地址类型(家庭、假期、办公室)等。例如: AddType 指的是一个列表,其中可以添加更多类型。