473,396 Members | 1,945 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

CHECK versus a Table for an enumeration

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
---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 12 '05 #1
7 2086
On Mon, 22 Dec 2003, 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'));
Will you ever in your wildest dreams need more or different values in
user_type? If not them go here. I user this for well known, limited
sets - Male/Female.
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.


This when there is a chance, any chance, you'll need to add to the list or
make changes to user_type_desc.
Rod
--
"Open Source Software - You usually get more than you pay for..."
"Build A Brighter Lamp :: Linux Apache {middleware} PostgreSQL"

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 12 '05 #2

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 |
+------------------------------+---------------------------------------------+

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 12 '05 #3
Thank you very much to you all. I'll choose the second option to be more
flexible.

Melanie
---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 12 '05 #4
On Mon, Dec 22, 2003 at 04:37:51PM -0500, Melanie Bergeron wrote:
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);


Check out the second article at
http://www.varlena.com/varlena/GeneralBits/42.php

It contains some discussion on this issue.

--
Alvaro Herrera (<alvherre[a]dcc.uchile.cl>)
"The West won the world not by the superiority of its ideas or values
or religion but rather by its superiority in applying organized violence.
Westerners often forget this fact, non-Westerners never do."
(Samuel P. Huntington)

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 12 '05 #5
Hello Melanie

If your set of items will by static and small, then you can use CHECK
constraint. I use it for five, items itemes.

You can write more simple this constraint

....
user_type TEXT NOT NULL CHECK (user_type IN ('Root','Admin','Standard')),

regards
Pavel Stehule


On Mon, 22 Dec 2003, 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
---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 12 '05 #6
On Mon, 22 Dec 2003, 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'));
Will you ever in your wildest dreams need more or different values in
user_type? If not them go here. I user this for well known, limited
sets - Male/Female.
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.


This when there is a chance, any chance, you'll need to add to the list or
make changes to user_type_desc.
Rod
--
"Open Source Software - You usually get more than you pay for..."
"Build A Brighter Lamp :: Linux Apache {middleware} PostgreSQL"

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 12 '05 #7
Thank you very much to you all. I'll choose the second option to be more
flexible.

Melanie
---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 12 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: -b | last post by:
I have a STATUS table consisting of a uid and description, that looks like this: 1 Accept 2 Accept with corrections 3 Reject I have a CHOICE table which referrs to the uid of...
1
by: Justin Wright | last post by:
I know that I can set up an enumeration as follows ( just typed in quick so may have syntax errors ): <xsd:simpleType name="colors"> <xsd:restriction base="xsd:string"> <xsd:enumeration...
3
by: Vithar | last post by:
I have a database that is being used as sort of a reports data warehouse. I use DTS packages to upload data from all the different sources. Right now I have it truncating the tables and appending...
3
by: Melanie Bergeron | last post by:
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')); ...
4
by: Alfetta159 | last post by:
I've been setting up a schema with the XML Designer in VS .NET 2003. The designer lets me set up a lot of things including a complex type that contains an unnamed complex type called modified. ...
4
by: Melissa | last post by:
I have a frontend file named CustomerApp and backend file named CustomerData. CustomerApp is at C:\Customer Database and CustomerData is at S:\Customer Database. Could someone help me with the code...
2
by: Jon Lapham | last post by:
I have a table that stores TEXT information. I need query this table to find *exact* matches to the TEXT... no regular expressions, no LIKE queries, etc. The TEXT could be from 1 to 10000+...
4
by: Stan R. | last post by:
Hello, I have xmllint and xsltproc installed and running on both my linux and win32 platforms, all seems good. I have a couple questions though. 1) If I have an external dtd file, which is...
3
by: Mr Flibble | last post by:
Here is some highly imaginative XML I've constructed to highlight what it is I'm trying to achieve. (Seems easier with an example). <foobars> <foo> <bar x="dog" colour="brown"/> <bar x="cat"...
15
by: null | last post by:
I am using the NotifyFilters enumeration type. In 'integer' the values are ored together, and I can use AND to check for equality like so If bNotifyFilter And NotifyFilters.Attributes Then...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.