Anytime this gets brought up (and it does, time and time again), before we argue further, I /really/ recommend reading;http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=6136&whichpage=2

and quazibubble's posts. Yes he's argumentative, but puts up an impressive reasoning.

Worked with a few people over the years who've tried todo weird and wacky stuff, get them spending 30mins going through that thread before arguing further and it's saved many a future project. (course, contractors who won't be around when there's later changes to the project love this stuff, but anyone having to maintain/expand systems are /really/ urged to read that link, and keep reading until it sinks in).

Robert Mahon-475361 (10/24/2010)Anytime this gets brought up (and it does, time and time again), before we argue further, I /really/ recommend reading;http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=6136&whichpage=2

and quazibubble's posts. Yes he's argumentative, but puts up an impressive reasoning.

I agree. I've just finished couple of weeks long job of repairing dozens of tables and relationships just because some creative admin before me had an idea that multicolumn non-surrogate PKs are cool. And I was repairing just one table.

I mean - there is something coled business logic!? and it does change over time. So every time it changes you will go throw very painful process of changing table PKs and all FK's and indexes related to it, and all ad-hoc queries and all database object querying it?? And than you will justify that with 2% storage benefits and 1,5% query performance (if so!)? good luck with that! for me, "ID int IDENTITY(1,1)" rules!

Personally I think most tables should have a surrogate key, there are exceptions, but the rule is have one imho.

Why? As I detail in my blog article - this is about concurrency, its about maintainability etc.

So yes, if there is a candidate key available on the table that is integer then yes I would still recomemnd a surrogate to abstract the data from the relational plumbing and get some stability from possible changes to the natural key(s) that would cause havoc for concurrency.

An interesting article, but there seems to be one aspect that has not been covered.

The article suggests that there is a slight overhead using a surrogate key (as an extra column is created ), however actually this can lead to a massive saving where foreign keys are concerned.

if your primary key is nvarchar(25) (50 bytes ish) then your foreign key in another table is also nvarchar(50) - this child table may have many times more data than your parent table, so using a surrogate key of INT will drop your storage and retreival costs significantly. (down to 4 Bytes)

so in a scenario where we only consider 1 table with 100,000 rows then yes we have an extra 400,000 bytes data, but in a scenario with 2 tables we actually save 4,600,000 bytes

ok my maths might be slightly off, and yes it's VAR so we don't always store the entire 50 bytes of data, so my saving is slightly exagerated, but it does demonstrate the point that a key should be as small as possible...

I'd love to see the article expanded to test the same scenario but using a join