Storing multiple values for a single field in a database

我们两清 提交于 2019-12-21 14:55:00

问题


Suppose i have a table with 3 fields

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 ?


回答1:


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).




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/10572987/storing-multiple-values-for-a-single-field-in-a-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!