SQLServerCentral Editorial

Overusing Identities

,

https://www.agiledata.org/images/dm101NotationSummary.gifI saw a post on Aaron Bertrand's blog recently about a bad habit to kick in building your tables. He choose using an identity column on every table as a habit that you should avoid. I clicked the link, expecting to disagree with Aaron since I tend to use identity columns quite liberally throughout my designs. I was glad to see Aaron admit that he uses them as well.

The post has some good advice about where we might be overusing identities, though I'm not sure I agree with the idea that a OrderDetails table doesn't need one. I've had places where you order additional quantities, ship separately, re-order on the same order, etc. that make having a simple  handle to that particular row nice. But in general I agree with Aaron.

But is overusing of identity a big problem? I tend to see most people building databases as beginning to intermediate data modelers. I'd probably include myself in that group as well, and rather than have them get confused about what a good natural key is, or building a complicated complex key, I think the default practice of just sticking a surrogate identity column on the table as the PK is a good idea. It's simple, and in the absence of knowing better, or having a reason not to do it, I think it's a good practice.

That doesn't mean that every table has to have an identity, and you certainly should make an effort to improve your modeling skills over time. Learn when it might not be appropriate, and build better models. Read posts like Aaron's and think about the consequences of adding in columns to your design that don't serve a purpose.

However I'll stand by the general rule. If you're in doubt, add that identity or GUID column as the PK. It will likely make life easier.

Steve Jones


The Voice of the DBA Podcasts

Everyday Jones

The podcast feeds are available at sqlservercentral.mevio.com. Comments are definitely appreciated and wanted, and you can get feeds from there.

You can also follow Steve Jones on Twitter:

Overall RSS Feed:

or now on iTunes!

Today's podcast features music by Everyday Jones. No relation, but I stumbled on to them and really like the music. Support this great duo at www.everydayjones.com.

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating