mysql - What's the best db structure to represent the relationships within a family if the base-object is a Person -
i have large db full or people called persons.
i want store relationship 1 in separate table.
i thinking this:
family person_ids: 123, 345, 678 relations: self, brother, daughter using 'self' flag indicate person referring relation-ship from. so, in example 123 man, 345 brother , 678 woman, daughter. i.e, gender information derived relationship.
is right way go it?
or more efficient have 2 persons per row , 1 relationship-type
person_ids: 123, 456 relation: brother -
person_ids: 123, 678 relation: daughter or better have male/female field per person , relation-ship table specify eg "sibling".
or should have table parents , store gender person?
table parents: parent_id: 123 child_id: 678 the aim display related people when person displayed. design should optimized performance & speed rather ease of administration.
thanks help.
it's many-to-many relationship: each person can have many relatives , relative of many people. assuming person table has primary key named id, have table, holds relationship between 2 people kind of relationship have. useful have table possible kinds of relationships, this:
relationship(id, kind) family(person_id, relative_id, relationship_id) so if have following data person , relationship tables:
person: relationship: id | name id | kind 1 | john 1 | father 2 | mike 2 | sister 3 | susan and following family table:
p_id | rel_id | relation_id 1 | 2 | 1 1 | 3 | 1 2 | 3 | 2 family table saying john father of mike , susan, , mike's sister susan. think approach, of course, in databases design, solution arguable.
Comments
Post a Comment