- Jun 7, 2000
- 9,099
- 19
- 81
I?m working on a project, and want some suggestions as to how I should create a database schema.
Existing tables:
Group (group_id, group_name...)
Person (person_id, name_last, name_first, address1...)
PersonGroup (persongroup_id, person_id, group_id, name_last, name_first, address1...)
The redundancy of fields between Person and PersonGroup is because PersonGroup must reflect the data as of when the person *joined* the group (never changes after insert), whereas the Person table must reflect the most current data (changes).
What I am trying to decide is how I should store data that applies to all of the people on a per-group basis. For example, group ?A? might require additional fields: date_of_birth, group_membership_number, favorite_color, forum_username, spouse_name, etc. Group ?B? might require additional fields: diet_type, favorite_food, computer_manufacturer, etc. That is to say, each group requires fields that are not required/optional/available for other groups. Because of that, I don?t want to add columns to ?PersonGroup?, and just leave columns unused for the appropriate groups (table ?Person? only requires information that is common to all groups). That would lead to a HUGE number of fields in the ?PersonGroup? table that are left null for various groups.
There are hundreds of groups. The number of people per group could be anywhere from 10 to 1,000.
There?s the entity-attribute-value way of approaching it:
GroupAddtnl (group_id, field_id, question)
PersonGroupAddtnl (persongroup_id, field_id, response)
And there?s the table creation way:
GroupAddtnl (group_id, field_id, question)
PersonGroupAddtnl_# (persongroup_id, field_1, field_2, field_3, field_4...)
And there are various ways to accomplish it that are somewhere in between. What do you recommend I consider, and why?
Existing tables:
Group (group_id, group_name...)
Person (person_id, name_last, name_first, address1...)
PersonGroup (persongroup_id, person_id, group_id, name_last, name_first, address1...)
The redundancy of fields between Person and PersonGroup is because PersonGroup must reflect the data as of when the person *joined* the group (never changes after insert), whereas the Person table must reflect the most current data (changes).
What I am trying to decide is how I should store data that applies to all of the people on a per-group basis. For example, group ?A? might require additional fields: date_of_birth, group_membership_number, favorite_color, forum_username, spouse_name, etc. Group ?B? might require additional fields: diet_type, favorite_food, computer_manufacturer, etc. That is to say, each group requires fields that are not required/optional/available for other groups. Because of that, I don?t want to add columns to ?PersonGroup?, and just leave columns unused for the appropriate groups (table ?Person? only requires information that is common to all groups). That would lead to a HUGE number of fields in the ?PersonGroup? table that are left null for various groups.
There are hundreds of groups. The number of people per group could be anywhere from 10 to 1,000.
There?s the entity-attribute-value way of approaching it:
GroupAddtnl (group_id, field_id, question)
PersonGroupAddtnl (persongroup_id, field_id, response)
And there?s the table creation way:
GroupAddtnl (group_id, field_id, question)
PersonGroupAddtnl_# (persongroup_id, field_1, field_2, field_3, field_4...)
And there are various ways to accomplish it that are somewhere in between. What do you recommend I consider, and why?
