If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > General > Database Concepts & Design > Why use a table with only one column?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-12-04, 16:41
ffinstad ffinstad is offline
Registered User
 
Join Date: Apr 2004
Posts: 4
Why use a table with only one column?

Is it common or good practice to have a table with only one column?
Reply With Quote
  #2 (permalink)  
Old 07-12-04, 16:57
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
Common, no. But it isn't inherently bad practice - it is perfectly valid in principle.
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote
  #3 (permalink)  
Old 07-13-04, 01:29
certus certus is offline
Registered User
 
Join Date: Dec 2003
Location: Canada
Posts: 710
What are you putting in the column?
__________________
visit: relationary
Reply With Quote
  #4 (permalink)  
Old 07-13-04, 08:57
ffinstad ffinstad is offline
Registered User
 
Join Date: Apr 2004
Posts: 4
Valid states for my app. For example, CA, NY, OR.

Just wondering if I should have an auto-incremented int ID column as well to serve as the primary key.
Reply With Quote
  #5 (permalink)  
Old 07-13-04, 09:02
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
Apart from meaning your table now had two columns instead of one, what purpose would that ID column serve? Answer: none. The state code itself is unique and will serve as a perfectly good, natural, primary key. Stick with your one column - or perhaps more usefully, add a description column that tells the user that 'NY' means 'New York' etc.
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote
  #6 (permalink)  
Old 07-13-04, 11:13
g00ber g00ber is offline
Registered User
 
Join Date: Jul 2004
Posts: 8
I would convert that table into a multi-purpose table like so...

Code:
TABLE: Categories
Code        Value
---------  --------
MONTH     January
MONTH     February
  :            :
MONTH     November
MONTH     December
WEEKDAY  Sunday
WEEKDAY  Monday
  :            :
WEEKDAY  Saturday
Reply With Quote
  #7 (permalink)  
Old 07-13-04, 11:18
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
Quote:
Originally Posted by g00ber
I would convert that table into a multi-purpose table like so...

Code:
TABLE: Categories
Code        Value
---------  --------
MONTH     January
MONTH     February
  :            :
MONTH     November
MONTH     December
WEEKDAY  Sunday
WEEKDAY  Monday
  :            :
WEEKDAY  Saturday
Would you really? You don't care much about data integrity then! What stops the user inserting 'January', 'NY' or 'blue' into a "weekday" column?
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote
  #8 (permalink)  
Old 07-13-04, 11:31
g00ber g00ber is offline
Registered User
 
Join Date: Jul 2004
Posts: 8
Quote:
Originally Posted by andrewst
Would you really? You don't care much about data integrity then! What stops the user inserting 'January', 'NY' or 'blue' into a "weekday" column?
This table would be considered a "setup" table.
So the dumb end-user (ex: data entry) would not be touching it.
Only a smart admin-user (ex: manager) would be playing with it.
Most likely the admin would set it up only once.
Ex: Add WEEKDAY and never add it again. Why? There are no more WEEKDAY!
Another Ex: There are only 50 STATES. Unless USA is acquiring Iraq as its 51'st state, then its safe to assume we only need to set the STATES up once.

Last edited by g00ber; 07-13-04 at 11:40.
Reply With Quote
  #9 (permalink)  
Old 07-13-04, 11:46
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
Quote:
Originally Posted by g00ber
This table would be considered a "setup" table.
So the dumb end-user (ex: data entry) would not be touching it.
Only a smart admin-user (ex: manager) would be playing with it.
Most likely the admin would set it up only once.
Ex: Add WEEKDAY and never add it again. Why? There are no more WEEKDAY!
Another Ex: There are only 50 STATES. Unless USA is acquiring Iraq as its 51'st state, then its safe to assume we only need to set the STATES up once.
But I wasn't referring to setting up the data in your "setup" table. I was referring to validating the data entered into all the other tables. Like this:

insert into customer (cust_id, state, delivery_day) values (1, 'december', 'green');

The concept I am alluding to is the foreign key. Your design precludes using foreign keys, and I don't like it!
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote
  #10 (permalink)  
Old 07-20-04, 08:36
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,605
Quote:
Originally Posted by andrewst
Apart from meaning your table now had two columns instead of one, what purpose would that ID column serve? Answer: none. The state code itself is unique and will serve as a perfectly good, natural, primary key. Stick with your one column - or perhaps more usefully, add a description column that tells the user that 'NY' means 'New York' etc.
I think that I'm probably genetically averse to the use of natural keys, but that aversion has come from experience... Things that "can't" change still seem to change on me, and at the worst possible times.

The population of California might decide to rename the state as "Ahnold-Stadt" and legislate the use of the abbreviation AS (they've actually done much weirder thing than that). This would cause great consternation, considering that Arkansas already used the state code of AS.

A natural key solution has no defense whatsoever against this kind of user-induced change. The problem is legislative, so there is no reasoning with it... You simply have to comply.

From a logical perspective, Tony has a good point and a natural key makes good sense. It still makes me nervous, since what is logical and what the real world requires are often two different things in my experience!

-PatP
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On