如何在数据库中保存婚姻关系 [英] how to save marital relationship in a database
本文介绍了如何在数据库中保存婚姻关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须将这些信息保存在数据库中
个人 - >已婚 - >人
我应该在哪里保存这些信息?我应该在这里应用什么样的设计模式?
谢谢!
解决方案>
如果你只能与一个人结婚:1:1
--------- ----
- 个人 -
-------------
id(key)
maried_to_id(外键)
如果你可以和多个人结婚,或者想要跟踪以前的标准,n:n
-------------
/ pre>
- 个人 -
------ -------
person_id(key)
-------------
- Mariage -
--- ----------
first_person_id(外键)
second_person_id(外键)
start_date
end_date
(也是first_person_id + second_person_id + date形成一个唯一的密钥,你可以省略日期,但是可以忽略不了)
I have to save this information in a database
Person -> is married to -> Person
Where should I save that information? What is the proper design pattern should I apply here?
Thank you!
解决方案If you can only be maried to one person: 1:1
------------- - Person - ------------- id (key) maried_to_id (foreign key)
If you can be maried to more than one person or want to keep track of previous mariages, n:n
------------- - Person - ------------- person_id (key) ------------- - Mariage - ------------- first_person_id (foreign key) second_person_id (foreign key) start_date end_date
(also first_person_id + second_person_id + date form a unique key for mariage. You could leave out the date, but then remariages wouldnt be tracked)
这篇关于如何在数据库中保存婚姻关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文