3

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?

Erwin Brandstetter
  • 185,527
  • 28
  • 463
  • 633
Mike81
  • 315
  • 1
  • 2
  • 11

3 Answers3

7

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 .

a1ex07
  • 9,060
  • 3
  • 27
  • 41
5

I would use an enum type for that.

Erwin Brandstetter
  • 185,527
  • 28
  • 463
  • 633
Ulrich Thomas Gabor
  • 2,694
  • 1
  • 18
  • 20
0

I always use a lookup table since your app may expand ("Organization" may become "Retail organization" once you add "Institutional organization" for example). A single location for the type name is great when you realize the type is slightly more specific or different than the original name would imply. Also, this is a great place to add values specific to the type like "CanHaveMultipleLogins" which VERY often get hard coded.

Ben Campbell
  • 236
  • 1
  • 4