Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12345»»»

Do You Really Need Surrogate Keys? Part 1 – Concepts and Methods Expand / Collapse
Author
Message
Posted Saturday, October 23, 2010 11:41 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Wednesday, November 12, 2014 1:22 PM
Points: 29, Visits: 237
Comments posted to this topic are about the item Do You Really Need Surrogate Keys? Part 1 – Concepts and Methods
Post #1009625
Posted Sunday, October 24, 2010 10:08 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, September 3, 2013 3:02 PM
Points: 21, Visits: 108
"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?

Post #1009773
Posted Sunday, October 24, 2010 11:20 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, July 10, 2014 9:44 PM
Points: 12, Visits: 40
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).

Post #1009788
Posted Monday, October 25, 2010 12:59 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Wednesday, December 11, 2013 3:11 AM
Points: 36, 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.
Post #1009817
Posted Monday, October 25, 2010 1:04 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, July 30, 2013 12:44 AM
Points: 9, 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.
Post #1009820
Posted Monday, October 25, 2010 1:53 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Saturday, November 22, 2014 12:34 AM
Points: 15, Visits: 50
Thanks for your post... If the Table has already has INTEGER type Natural Key, would you still recommend the Surrogate Key ...
Post #1009827
Posted Monday, October 25, 2010 2:01 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, July 10, 2014 9:44 PM
Points: 12, Visits: 40
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?
Post #1009828
Posted Monday, October 25, 2010 2:10 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, July 30, 2013 12:44 AM
Points: 9, 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.
Post #1009830
Posted Monday, October 25, 2010 3:39 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Friday, August 8, 2014 3:25 AM
Points: 2,283, Visits: 781
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
Post #1009856
Posted Monday, October 25, 2010 3:50 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Sunday, July 3, 2011 7:09 AM
Points: 233, 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
Post #1009859
« Prev Topic | Next Topic »

Add to briefcase 12345»»»

Permissions Expand / Collapse