Dev Shed Lounge
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsOtherDev Shed Lounge

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 3rd, 2001, 07:45 PM
mcsimon mcsimon is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2000
Posts: 179 mcsimon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 37 m 38 sec
Reputation Power: 14
Send a message via AIM to mcsimon Send a message via Yahoo to mcsimon
Database design question

Hi all

When creating a table, I make an autonumber column so I can make it primary key. Then I'll use that number when making relationships. But look at the following.

I have rows that I'd like to reference as:

1.1 | some field | some field
1.2 | some field | some field
1.3 | some field | some field
1.4 | some field | some field
2.1 | some field | some field
2.2 | some field | some field
2.3 | some field | some field
2.4 | some field | some field
3.1 | some field | some field
3.2 | some field | some field
3.3 | some field | some field
etc....

What would you recommend as far as creating a primary key?
An autonumber column,
A unique decimal column (ie 2.1,2.2 etc),
or combine two indexed columns like
1 | 1 | some field | some field
1 | 2 | some field | some field
etc.

By the way, that first number in 1+n.n is a foreign key to another table.

Sorry if this sounds confusing. I just want to know if you can combine two columns to make a unique key. If you can, are there any drawbacks.

Thanks

Reply With Quote
  #2  
Old August 4th, 2001, 02:46 PM
Pressly Pressly is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2001
Posts: 48 Pressly User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 13
Lightbulb Increment by Integer

If you plan to use auto_increment, you will need to specify the key field as INT(size) and NOT NULL. If you want to use the foreign key from another table, plus another field combined to yeild a unique key, that will work too.

Reply With Quote
  #3  
Old August 5th, 2001, 12:17 AM
mcsimon mcsimon is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2000
Posts: 179 mcsimon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 37 m 38 sec
Reputation Power: 14
Send a message via AIM to mcsimon Send a message via Yahoo to mcsimon
I was pretty confident that using a foreign key combined with another column would be good enough as a unique key, but I'm dreading the kind of select statements I'll need to use. I will also have another table that will contain two foreign keys and another column to make a unique identifier.

Thanks for the feedback!

Reply With Quote
Reply

Viewing: Dev Shed ForumsOtherDev Shed Lounge > Database design question

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap