PhatoseAlpha
Platinum Member
I'm working on a project that involves handling customer accounts. In working out the database specs though, I've run into a situation that I'm sure someone here as run into before.
We need to handle accounts, some of which are tied to a person, some of which are tied to a company. I don't want to just make them all 1 record which includes a name field and a company field, as that would seem to violate normalization rules. In code, I would just make the field an interface of have both person and company implement it. But in a database, I don't know.
I see two possibilities - one is to make a third table, entities, and reference that from both person and company fields, and in the accounts reference the entity table. I could also have the account have two fields, one indicating whether the id being referenced was a person on a company then the id - but that prevents me from using foreign key restraints for that field.
I figure this situation has come up before thousand of times, and there's probably a best practice for it - one of those two, or perhaps a third option I haven't thought of. My googling skills have failed me though. Any recommendations?
We need to handle accounts, some of which are tied to a person, some of which are tied to a company. I don't want to just make them all 1 record which includes a name field and a company field, as that would seem to violate normalization rules. In code, I would just make the field an interface of have both person and company implement it. But in a database, I don't know.
I see two possibilities - one is to make a third table, entities, and reference that from both person and company fields, and in the accounts reference the entity table. I could also have the account have two fields, one indicating whether the id being referenced was a person on a company then the id - but that prevents me from using foreign key restraints for that field.
I figure this situation has come up before thousand of times, and there's probably a best practice for it - one of those two, or perhaps a third option I haven't thought of. My googling skills have failed me though. Any recommendations?