SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Do You Really Need Surrogate Keys? Part 1 – Concepts and Methods


Do You Really Need Surrogate Keys? Part 1 – Concepts and Methods

Author
Message
wagner crivelini
wagner crivelini
Old Hand
Old Hand (310 reputation)Old Hand (310 reputation)Old Hand (310 reputation)Old Hand (310 reputation)Old Hand (310 reputation)Old Hand (310 reputation)Old Hand (310 reputation)Old Hand (310 reputation)

Group: General Forum Members
Points: 310 Visits: 282
Comments posted to this topic are about the item Do You Really Need Surrogate Keys? Part 1 – Concepts and Methods
admin-499013
admin-499013
SSC Journeyman
SSC Journeyman (77 reputation)SSC Journeyman (77 reputation)SSC Journeyman (77 reputation)SSC Journeyman (77 reputation)SSC Journeyman (77 reputation)SSC Journeyman (77 reputation)SSC Journeyman (77 reputation)SSC Journeyman (77 reputation)

Group: General Forum Members
Points: 77 Visits: 114
"UPDATE dbo.tblProduct*
SET Color = 'Black'
WHERE Name = 'ML Mountain Frame-W - Silver, 42';"


I might be missing something but how can you expect a surrogate key to improve performance if you are not referencing it?
Robert Mahon-475361
Robert Mahon-475361
SSC Rookie
SSC Rookie (46 reputation)SSC Rookie (46 reputation)SSC Rookie (46 reputation)SSC Rookie (46 reputation)SSC Rookie (46 reputation)SSC Rookie (46 reputation)SSC Rookie (46 reputation)SSC Rookie (46 reputation)

Group: General Forum Members
Points: 46 Visits: 41
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).
darko IS
darko IS
SSC-Enthusiastic
SSC-Enthusiastic (112 reputation)SSC-Enthusiastic (112 reputation)SSC-Enthusiastic (112 reputation)SSC-Enthusiastic (112 reputation)SSC-Enthusiastic (112 reputation)SSC-Enthusiastic (112 reputation)SSC-Enthusiastic (112 reputation)SSC-Enthusiastic (112 reputation)

Group: General Forum Members
Points: 112 Visits: 184
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!

If you don't like how things are, change it! You're not a tree.
tonyrogerson-498793
tonyrogerson-498793
Valued Member
Valued Member (69 reputation)Valued Member (69 reputation)Valued Member (69 reputation)Valued Member (69 reputation)Valued Member (69 reputation)Valued Member (69 reputation)Valued Member (69 reputation)Valued Member (69 reputation)

Group: General Forum Members
Points: 69 Visits: 38
I wrote a blog article a while back on the theory on surrogate keys based around Codd and Date.

The link: http://sqlblogcasts.com/blogs/tonyrogerson/archive/2010/03/13/database-design-surrogate-keys-part-1-of-many-rules-for-surrogate-keys-e-f-codd-and-c-j-date-research-and-problems-they-solve.aspx

Reminds me - I need to go back and finish the other parts I said I would.

Surrogates are a good thing and save us from all sorts of problems.

Tony.
kasisriharsharao
kasisriharsharao
SSC Journeyman
SSC Journeyman (85 reputation)SSC Journeyman (85 reputation)SSC Journeyman (85 reputation)SSC Journeyman (85 reputation)SSC Journeyman (85 reputation)SSC Journeyman (85 reputation)SSC Journeyman (85 reputation)SSC Journeyman (85 reputation)

Group: General Forum Members
Points: 85 Visits: 54
Thanks for your post... If the Table has already has INTEGER type Natural Key, would you still recommend the Surrogate Key ...
Robert Mahon-475361
Robert Mahon-475361
SSC Rookie
SSC Rookie (46 reputation)SSC Rookie (46 reputation)SSC Rookie (46 reputation)SSC Rookie (46 reputation)SSC Rookie (46 reputation)SSC Rookie (46 reputation)SSC Rookie (46 reputation)SSC Rookie (46 reputation)

Group: General Forum Members
Points: 46 Visits: 41
kasisriharsharao (10/25/2010)
Thanks for your post... If the Table has already has INTEGER type Natural Key, would you still recommend the Surrogate Key ...


Read;
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=6136&whichpage=2

All of quazibubble's posts, including his later posts from another account when the first one gets banned and you'll have your answer.

Out of curiosity though, what integer natural key are you thinking?
tonyrogerson-498793
tonyrogerson-498793
Valued Member
Valued Member (69 reputation)Valued Member (69 reputation)Valued Member (69 reputation)Valued Member (69 reputation)Valued Member (69 reputation)Valued Member (69 reputation)Valued Member (69 reputation)Valued Member (69 reputation)

Group: General Forum Members
Points: 69 Visits: 38
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.

Tony.
MVDBA
MVDBA
SSCertifiable
SSCertifiable (6.6K reputation)SSCertifiable (6.6K reputation)SSCertifiable (6.6K reputation)SSCertifiable (6.6K reputation)SSCertifiable (6.6K reputation)SSCertifiable (6.6K reputation)SSCertifiable (6.6K reputation)SSCertifiable (6.6K reputation)

Group: General Forum Members
Points: 6633 Visits: 860
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

MVDBA
ta.bu.shi.da.yu
ta.bu.shi.da.yu
Ten Centuries
Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)

Group: General Forum Members
Points: 1059 Visits: 494
Robert Mahon-475361 (10/25/2010)
kasisriharsharao (10/25/2010)
Thanks for your post... If the Table has already has INTEGER type Natural Key, would you still recommend the Surrogate Key ...


Read;
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=6136&whichpage=2

All of quazibubble's posts, including his later posts from another account when the first one gets banned and you'll have your answer.

Out of curiosity though, what integer natural key are you thinking?


He certainly makes some good points.

However, if you want to see the best point made, it is the one by JCamburn at 05/23/2003 : 23:19:21

See http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=6136&whichpage=6

He actually gets it.

Random Technical Stuff
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search