在数据库中为单个字段存储多个值 [英] Storing multiple values for a single field in a database
问题描述
假设我有一个包含3个字段的表
Suppose i have a table with 3 fields
Person_id,姓名和地址.现在的问题是一个人可以有多个地址.原子值的原理说数据应该是原子的.
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.
那我应该如何为一个人存储多个地址?
So then how am i suppose to store multiple addresses for a single person ?
推荐答案
您应该创建一个ADDRESS
表,该表具有将其链接到PERSON
记录(即PERSON_ID
)的外键.这是关系数据库的关系"组件,这就是为什么它比平面文件(就像一个表)更灵活的原因.
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).
这篇关于在数据库中为单个字段存储多个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!