HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

To normalize or not to normalize for few distinct values

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
normalizedistinctfewforvaluesnot

Problem

Assuming in a Postgres database, you have a table called party, which can have less than 5 well-defined party_types such as 'Person' or 'Organization'.

Would you store the party_type in the party table (e.g. party_type = 'Person') or normalize it (e.g. party.party_type = 1 and party_type(id, name) = (1, 'Person'))?

And why?

Solution

If you are implementing party-role-relationship model or part of it, having party_type as a separate entity is very important. You may have many more tables with foreign key to party_type (for instance, to limit applicability of certain roles to particular party type[s], or to enforce relationships between different types of parties, etc). Using check constraints in any form (including enums) in such cases would hide the logic and make maintenance harder .

Context

StackExchange Database Administrators Q#59509, answer score: 7

Revisions (0)

No revisions yet.