Re: database design best pratice help

From: Thomas Kellerer <spam_eater(at)gmx(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: database design best pratice help
Date: 2013-01-28 10:02:21
Message-ID: ke5i9r$l6s$1@ger.gmane.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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 the proper 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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Albe Laurenz 2013-01-28 10:13:25 Re: database design best pratice help
Previous Message Jose Soares 2013-01-28 09:45:41 database design best pratice help