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 > PK vs. Identity

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-18-11, 01:29
msanchez msanchez is offline
Registered User
 
Join Date: Mar 2011
Posts: 1
Question PK vs. Identity

As a software developer, I have a solid understanding of relational databases and normalization and have designed many. But what is the best or most pragmatic answer to the whole debate of 'when to use the real candidate key, when to use an identity PK', and the byproduct concerns around joining on keys that are strings (varchar) as opposed to an identity?
Reply With Quote
  #2 (permalink)  
Old 03-18-11, 09:18
skempins skempins is offline
Registered User
 
Join Date: Sep 2003
Location: NE Florida w/ view of co-workers
Posts: 32
I found a writeup on this exact question: Choosing a Primary Key: Natural or Surrogate?

About half way down it sums up the tradeoff
Quote:
The advantage of natural keys is that they exist already, you don’t need to introduce a new “unnatural” value to your data schema. However, the disadvantage of natural keys is that because they have business meaning they are effectively coupled to your business: you may need to rework your key when your business requirements change.
Personally I have been burned more than once by choosing a natural key only to have the business change later on. My rule of thumb is to go with surrogates unless it can be guaranteed that the natural will not change definition.
Reply With Quote
  #3 (permalink)  
Old 03-18-11, 12:10
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
an even more important rule of thumb is: never assign a surrogate key until you have also declared a UNIQUE key elsewhere in the same table
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #4 (permalink)  
Old 03-21-11, 09:43
blindman blindman is offline
World Class Flame Warrior
 
Join Date: Jun 2003
Location: Ohio
Posts: 11,726
Agree with that.
I use surrogate keys on all my tables, for consistency of design and coding. But I also declare a unique natural key.
__________________
If it's not practically useful, then it's practically useless.

blindman
www.chess.com: "sqlblindman"
Reply With Quote
Reply

Tags
design, identity, joins, primary key

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