Re: database design best pratice help - Mailing list pgsql-general

From Thomas Kellerer
Subject Re: database design best pratice help
Date
Msg-id ke5i9r$l6s$1@ger.gmane.org
Whole thread Raw
In response to database design best pratice help  (Jose Soares <jose.soares@sferacarta.com>)
List pgsql-general
I'll answer with the same things I did on the Oracle list :)

> code
> description
>
> To avoid to have a so great number of similar tables in the db
> I wonder if it is a good idea to unify all these tables in one big table
> like this:
>
> id
> code
> table_ name
> description
>
> The advantages are:
>
> 1. only one table in the db instead of 100

That's not an advantage.

> 2. only one controller to manage the table

Why? You can also have a single controller with many tables.

With a single table the controller needs to know the code. With multiple tables the controller needs to know the table
name.
I don't see any difference there.


> Is there any negative point that I don't see?

Yes, you can't prevent storing the "wrong" code in a related table as you cannot have a foreign key to it.

Assume you have a list of codes for "order status" and a list of codes for employee status. With two lookup tables (and
theproper foreign keys) you can make sure that only a valid employee status is stored in the employee table. 

With the single table you can't prevent storing a value for "order status" as the employee table.

Your design is an anti-pattern which has a name: "one true lookup table".

Thomas


pgsql-general by date:

Previous
From: Jose Soares
Date:
Subject: database design best pratice help
Next
From: Albe Laurenz
Date:
Subject: Re: database design best pratice help