Re: CHECK versus a Table for an enumeration
От | Paul Thomas |
---|---|
Тема | Re: CHECK versus a Table for an enumeration |
Дата | |
Msg-id | 20031223002759.C27585@bacon обсуждение исходный текст |
Ответ на | CHECK versus a Table for an enumeration (Melanie Bergeron <mbergeron_pg@globeecom.com>) |
Список | 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 | +------------------------------+---------------------------------------------+
В списке pgsql-general по дате отправления: