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
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 >:(
For names, I recommend keeping it simple. Have a name table with three columns:
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:
Maria de los Angeles Gomez Portillo
Abdul Rahmin ibn Saeed ibn Abd al-Aziz al-Filasteeni
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?