views:

67

answers:

4

Hello,

What are the adverse effects of having too many lookup tables in the database?

I have to incorportate too many Enumerations, based on the applications.

What would experts advice?

+7  A: 

Initially you have to ask yourself "how many is too many?". If there is a logical relation between two tables, there has to be a FK.

If you don't need the related tables anywhere within the database, you could consider to remove them and use a CHECK constraint with an "IN" clause to enforce data validity. Though, this would cause an alteration of the table with each new value within the enumeration.

My personal advice is to keep the FKs and the tables. It's a clear solution and the database is way better to maintain if there is a describing text available for all those numbers

Greets Flo

Florian Reischl
A: 

The Whole point of lookup data is that there is a finite list of valid identifiers for a specific field. if those specific fields are used in procedures or where statements to determine the correct process path or the limit the select list, then there is no such thing as too many lookups.

if it is not a finite list of identifiers for a specific process or where clause then they should not be a lookup value.

two types of fields that come to mind which might be considered lookup values but don't necessarily need to be.

City and Province/state:

There is a finite list of these but because there are sooo many you might not want to make a lookup for these.

greektreat
+3  A: 

As Florian, I like a lot more to have tons of Foreign Keys then to have CHECK IN (..) - for a simple reason: you can insert other records on your tables.

Maintaning CHECK IN () is a much bigger problem. Imagine this scenario:

CREATE TABLE street
(
   id serial not null,
   st_type varchar(20) not null,
   st_name varchar(100) not null,
   constraint street_pk primary key (id)
   constraint street_type_check check st_type in ('STREET','AVENUE','SQUARE')
);

You have 1000 rows with those types checked, correct? If you need to add another one, you will need to drop the constraint and recreate it.

IF you take a item off that list, like SQUARE, what will happen to the rows already commited (and checked at moment of insertion) that have that type? They will still keep an invalid type.

Tables and Foreign Keys are easier to maintain and keep track of.

George
+2  A: 

Let me tell how awful it is to have too few lookup tables. THe orginal designers at one place I worked decided to put all lookups into one table and define what the lookups were for using a typeid. This caused almost all queries to hit this table to get the lookup descriptive value causing a performance jam.

Further, without separate lookups, the fields that took the typeid were not constrained by the values appropriate to that field because a foreign key can only be on the the whole table not a chunk. So the filed that stored the clientid might accidentally contain the value for a user group. This caused data integrity problems and made reporting much more difficult as we had to intepret values that didn't make sense in context. There is no prize for using too few tables, in fact it is often an anti-pattern in database design.

Create 1000 lookup tables if that is what you need.

HLGEM