Chris's Wiki :: blog/python/DjangoImplicitPKAdvantage Commentshttps://utcc.utoronto.ca/~cks/space/blog/python/DjangoImplicitPKAdvantage?atomcommentsDWiki2011-01-31T10:20:49ZRecent comments in Chris's Wiki :: blog/python/DjangoImplicitPKAdvantage.From 192.148.117.85 on /blog/python/DjangoImplicitPKAdvantagetag:CSpace:blog/python/DjangoImplicitPKAdvantage:0714b90efecf78aa4454b9f69b81ca1a832f2037From 192.148.117.85<div class="wikitext"><p>Ah, the joys of <a href="http://en.wikipedia.org/wiki/Surrogate_key">surrogate keys</a>. It's the immutability I love the most. The performance advantages of an integer are nice as well.</p>
<p>My general rule is use a surrogate key as the primary key (typically a <code>serial</code> in PostgreSQL) and place a unique constraint on whatever makes the row unique. Any table which represents external/real world data should have an obvious candidate key. If you can't find it, you're probably doing it wrong. </p>
<p>I have worked on databases which use normal candidate keys as the primary key. I'd prefer not to do that again.</p>
<p>- <a href="http://jasoncodes.com/">Jason Weathered</a></p>
</div>2011-01-31T10:20:49Z