用於表示家庭,家庭和關系的數據庫模型

[英]Database Model to Represent Families, Households, and Relationships


Here's my situation. I am building a database to track relationships between people and households. Typically, everything is tied to a "head of household".

這是我的情況。我正在建立一個數據庫來跟蹤人與家庭之間的關系。通常,一切都與“戶主”聯系在一起。

I am trying to avoid this as it creates problems when people move (i.e. brother finally gets a job and moves out) or families break up (i.e. dad and mom get divorced, household is now split into two, some kids stay with mom, some with dad).

我試圖避免這種情況,因為它會在人們搬家時產生問題(即兄弟最終找到工作並搬出去)或家庭破裂(即爸爸和媽媽離婚,家庭現在分成兩部分,一些孩子留在媽媽,一些和爸爸一起)。

It is a huge challenge to figure out how to cascade the data when the model is based on HOH. My approach is split the data into 3 tables, household, person, and relationship. hh just stores an address and an id. relationship stores a person_id_a, person_id_b and a relationship code (i.e. 1 = sibling). And person stores the names, and a hh_id. This way, if a family splits up, I can change the relationship between mom and dad to NULL and create a new hh for dad and any kids that came with him without disrupting the other relationships.![Here is what the model looks like:

當模型基於HOH時,弄清楚如何級聯數據是一個巨大的挑戰。我的方法是將數據分成3個表,家庭,人和關系。 ......只是存儲一個地址和一個id。 relationship存儲person_id_a,person_id_b和關系代碼(即1 =兄弟)。人存儲名稱和hh_id。這樣,如果一個家庭分手,我可以將媽媽和爸爸之間的關系改為NULL並為爸爸和任何跟隨他的孩子創建一個新的......而不會破壞其他關系。![這是模型的樣子:

Person -person_id -hh_id

Person -person_id -hh_id

Relationship -person_id_a -person_id_b -relationship_cd

關系-person_id_a -person_id_b -relationship_cd

Household -hh_id -address

家庭-hh_id -address

Does this makes sense to you guys? Can you think of any reason this wouldn't work, or think there is a better model out there?

這對你們有意義嗎?你能想到任何不起作用的原因,或者認為那里有更好的模型嗎?

Sorry, I know this is a bit depressing. All these divorces making my job difficult >:(

對不起,我知道這有點令人沮喪。所有這些離婚讓我的工作變得困難> :(

1 个解决方案

#1


For names, I recommend keeping it simple. Have a name table with three columns:

對於名字,我建議保持簡單。有一個包含三列的名稱表:

  • GivenNames
  • FamilyNames
  • NameType {legal, alternate}
  • NameType {legal,alternate}

You can even just go with a single name column for FullName instead. I would not have middle name, married name, maiden name, paternal surname, nickname, or any other "special" name columns. It will only complicate any name searching algorithm, and confuse data entry. Here are some example names to consider:

您甚至可以使用FullName的單個名稱列。我不會有中間名,已婚姓名,婚前姓,父姓,昵稱或任何其他“特殊”名稱列。它只會使任何名稱搜索算法復雜化,並混淆數據輸入。以下是一些需要考慮的示例名稱:

  • John Paul Smith
  • 約翰保羅史密斯

  • Mary Paul Smith
  • 瑪麗保羅史密斯

  • John Henry William Artemis Williams
  • 約翰亨利威廉阿爾特彌斯威廉姆斯

  • Maria de los Angeles Gomez Portillo
  • Maria de los Angeles Gomez Portillo

  • Abdul Rahmin ibn Saeed ibn Abd al-Aziz al-Filasteeni
  • Abdul Rahmin ibn Saeed ibn Abd al-Aziz al-Filasteeni

  • Abdulla

So what do these names show? The first is pretty normal english name, with first (John), middle (Paul) and last (Smith). The second is Mary. She has no middle name in her legal name. Her maiden surname is Paul, and her married surname is Smith. She uses both, without a hyphen. The third is John. His parents thought it would be awesome to give him three middle names. The fourth is a Hispanic name, and that's her full legal name. Her given name is Maria de los Angeles. "de los Angeles" is part of her fist name. She does not have a middle name. Her father's first surname was Gomez. Her mother's first surname was Portillo. So Maria's full surname is Gomez Portillo. She may commonly go by just Maria Gomez because she's so tired of her name getting entered in a mangled way. Technically, Portillo is her "last" name, but if she were to use only one of her two surnames, she would use the first one (the paternal surname). The fifth is Abdul Rahmin, son of Saeed, grandson of Abd al-Aziz, of Palestine. Have fun putting this in first/middle/last. Abdul Rahmin is his given name. All the rest are family names. The final one is Abdulla. He's from Afghanistan. It's not uncommon for folks to have no last name there. He is simply Abdulla. He also doesn't know his birthdate, because where he was from, they don't care about that (this was often the case in American colonial times...caring about birthdates is kind of a recent thing in many cultures).

那么這些名字顯示了什么?第一個是非常正常的英文名字,第一個(約翰),中間(保羅)和最后一個(史密斯)。第二個是瑪麗。她的法定名稱中沒有中間名。她的處女姓是保羅,她的姓氏是史密斯。她使用兩者,沒有連字符。第三是約翰。他的父母認為給他三個中間名是很棒的。第四個是西班牙裔名字,這是她的完整法定名稱。她的名字是Maria de los Angeles。 “de los Angeles”是她名字的一部分。她沒有中間名。她父親的第一個姓是戈麥斯。她母親的第一個姓氏是Portillo。瑪麗亞的全名是Gomez Portillo。她可能常常只去瑪麗亞戈麥斯,因為她已經厭倦了她的名字以一種錯誤的方式進入。從技術上講,Portillo是她的“最后”名字,但如果她只使用她的兩個姓氏中的一個,她會使用第一個(父姓)。第五位是巴勒斯坦人阿卜杜勒·阿齊茲的孫子賽義德的兒子阿卜杜勒·拉赫明。把它放在第一個/中間/最后一個很有趣。 Abdul Rahmin是他的名字。其余的都是姓氏。最后一個是阿卜杜拉。他來自阿富汗。人們在那里沒有姓氏並不少見。他簡直就是阿卜杜拉。他也不知道他的出生日期,因為他來自哪里,他們並不關心這一點(在美國殖民時期經常出現這種情況......在許多文化中,關心出生日期是一種近期的事情)。

You should have a separate name table, so a person can have more than one name row. An example illustrates one of the many, many reasons why. Mary Smith hates her common name. So she gets it legally changed to Sunshine Lollipop Countess of the Universe. She sort of regrets that two years later. Now, she sometimes uses Mary Smith, and sometimes Sunshine Universe, depending on the phase of the moon. Store both of them and you find her either way.

您應該有一個單獨的名稱表,因此一個人可以有多個名稱行。一個例子說明了其中一個原因。瑪麗史密斯討厭她的俗名。因此,她將其合法地改為陽光棒棒糖宇宙伯爵夫人。兩年后,她有點后悔。現在,她有時使用瑪麗史密斯,有時使用陽光宇宙,取決於月亮的相位。存放它們,你找到她的方式。

However you do it, people will mangle names in every way imaginable (and some you wouldn't imagine), and enter them differently at different times. If you don't accept that as a given, you'll have problems.

無論你如何做,人們都會以各種可想象的方式(以及一些你無法想象的方式)破壞名字,並在不同的時間以不同的方式輸入它們。如果你不接受這個,那你就會遇到問題。

For households, as I mentioned in my comments, you may want to support a many-to-many relationship. A household can have zero to many people, and a person can have zero to many households. This is a little tricky though, because it depends on what your define as a household. You may feel the need to denote one as primary, but consider a child that spends half her time with her mother, and half with her father. Which one is primary?

對於家庭,正如我在評論中提到的,您可能希望支持多對多關系。一個家庭可以有零到多人,一個人可以有零到多個家庭。這有點棘手,因為它取決於你定義的家庭。你可能覺得有必要將一個人稱為小學,但要考慮一個孩子花一半時間與母親在一起,另一半與父親在一起。哪一個是主要的?


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2015/05/08/72541fb871014fc39bb42db1b0e5112e.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com