Results 1 to 10 of 10
  1. #1
    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.)?

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    no, not really

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Feb 2009
    Posts
    104

    thanks

    Cool; primary keys can be descriptive.

  4. #4
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    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"
    www.LobsterShot.blogspot.com

  5. #5
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912

    Thumbs up

    It took me one attempt to look it up
    Testimonial:
    pootle flump
    ur codings are working excelent.

  6. #6
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    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:
    pootle flump
    ur codings are working excelent.

  7. #7
    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.

  8. #8
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    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 ... )
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  9. #9
    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.

  10. #10
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    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"
    www.LobsterShot.blogspot.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •