Re: CHECK versus a Table for an enumeration

From: Paul Thomas <paul(at)tmsl(dot)demon(dot)co(dot)uk>
To: "pgsql-general (at) postgresql (dot) org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: CHECK versus a Table for an enumeration
Date: 2003-12-23 00:27:59
Message-ID: 20031223002759.C27585@bacon
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


On 22/12/2003 21:37 Melanie Bergeron wrote:
> Hi all!
>
> I want to know what's better between these 2 solutions :
>
> CREATE TABLE user (
> ...
> user_type text CHECK(user_type='Root' OR user_type = 'Admin' OR
> user_type = 'Standard'));
>
> or the following :
>
> CREATE TABLE user_type(
> user_type_id integer PRIMARY KEY,
> user_type_desc text);
>
> CREATE TABLE user (
> ...
> user_type_id integer,
> CONSTRAINT user_type_exists FOREIGN KEY (user_type_id) REFERENCES
> user(user_type_id));
>
> I am really confused so I'll wait for your advices.
>
> Thanks,
>
> Melanie

just my personal opinion but here goes:

For the example you've provided I don't think theres much in it. The
second version would give you ability to change the text of the user type
if that were important and to add new user types without having to alter
constraints. So if I _had_ to choose, I'd take the second option.

HTH

--
Paul Thomas
+------------------------------+---------------------------------------------+
| Thomas Micro Systems Limited | Software Solutions for the Smaller
Business |
| Computer Consultants |
http://www.thomas-micro-systems-ltd.co.uk |
+------------------------------+---------------------------------------------+

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Alvaro Herrera 2003-12-23 00:56:02 Re: CHECK versus a Table for an enumeration
Previous Message Dann Corbit 2003-12-23 00:03:10 Re: COPY - Ignore Problems