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 > primary keys with variable length?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-23-09, 21:29
rbfree rbfree is offline
Registered User
 
Join Date: Feb 2009
Posts: 104
primary keys with variable length?

Is there any problem with using a varchar type for a primary key (in terms of efficiency, etc.)?
Reply With Quote
  #2 (permalink)  
Old 03-23-09, 22:17
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
no, not really

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 03-24-09, 00:04
rbfree rbfree is offline
Registered User
 
Join Date: Feb 2009
Posts: 104
thanks

Cool; primary keys can be descriptive.
Reply With Quote
  #4 (permalink)  
Old 03-24-09, 10:41
blindman blindman is offline
World Class Flame Warrior
 
Join Date: Jun 2003
Location: Ohio
Posts: 11,726
Yes, in which case they are frequently referred to as "natural keys". The corollary would be "surrogate keys", which by definition convey no information about the record they represent.
My God. I am embarrassed to admit it took me three attempts with the spell-checker to spell corollary correctly.
__________________
If it's not practically useful, then it's practically useless.

blindman
www.chess.com: "sqlblindman"
Reply With Quote
  #5 (permalink)  
Old 03-24-09, 11:16
pootle flump pootle flump is offline
King of Understatement
 
Join Date: Feb 2004
Location: One Flump in One Place
Posts: 14,905
Thumbs up

It took me one attempt to look it up
__________________
Testimonial:
Quote:
pootle flump
ur codings are working excelent.
Reply With Quote
  #6 (permalink)  
Old 03-24-09, 11:20
pootle flump pootle flump is offline
King of Understatement
 
Join Date: Feb 2004
Location: One Flump in One Place
Posts: 14,905
Quote:
Originally Posted by rbfree
Is there any problem with using a varchar type for a primary key (in terms of efficiency, etc.)?
Depending how you define efficiency, the specific nature (maximum length for example) of the primary key data, whether or not you use it in foreign keys and also what you propose instead of the natural key, there *might* be a "problem".

But Rudy is quite correct - there's nothing inheritantly wrong with varchar PKs.
__________________
Testimonial:
Quote:
pootle flump
ur codings are working excelent.
Reply With Quote
  #7 (permalink)  
Old 03-24-09, 11:50
rbfree rbfree is offline
Registered User
 
Join Date: Feb 2009
Posts: 104
thanks blindman

I appreciate this information. Re. the spelling... remember, the more we know, the more we can forget (apology of a geezer... though not to imply that anyone but me is a geezer...)

Quote:
Originally Posted by blindman
Yes, in which case they are frequently referred to as "natural keys". The corollary would be "surrogate keys", which by definition convey no information about the record they represent.
My God. I am embarrassed to admit it took me three attempts with the spell-checker to spell corollary correctly.
Reply With Quote
  #8 (permalink)  
Old 03-24-09, 11:58
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
varchar keys aren't necessarily natural keys

and the word you were looking for, blindman, is opposite, not corollary

(apology of a nitpicking geezer, or a picnicking teaser, or ... )
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #9 (permalink)  
Old 03-24-09, 12:11
rbfree rbfree is offline
Registered User
 
Join Date: Feb 2009
Posts: 104
thanks all and semantic quibble for r

These primary keys that I'm talking about will have short max lengths -- VARCHAR(6) ... or something under (10), whatever they might be.

Re. opposition and corollary, an opposition can be offered as a corollary.... a lovely case of non-conflicting apposition.
Reply With Quote
  #10 (permalink)  
Old 03-24-09, 14:14
blindman blindman is offline
World Class Flame Warrior
 
Join Date: Jun 2003
Location: Ohio
Posts: 11,726
Actually, I think the most appropriate term would be "complement".
__________________
If it's not practically useful, then it's practically useless.

blindman
www.chess.com: "sqlblindman"
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