|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Wednesday, January 30, 2013 10:57 AM
Points: 28,
Visits: 173
|
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Friday, April 26, 2013 4:37 AM
Points: 21,
Visits: 107
|
|
"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?
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Friday, November 05, 2010 10:25 PM
Points: 12,
Visits: 39
|
|
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).
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Tuesday, May 21, 2013 6:08 AM
Points: 36,
Visits: 178
|
|
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.
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Thursday, November 22, 2012 2:44 AM
Points: 9,
Visits: 36
|
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Friday, August 17, 2012 5:53 PM
Points: 15,
Visits: 49
|
|
| Thanks for your post... If the Table has already has INTEGER type Natural Key, would you still recommend the Surrogate Key ...
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Friday, November 05, 2010 10:25 PM
Points: 12,
Visits: 39
|
|
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?
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Thursday, November 22, 2012 2:44 AM
Points: 9,
Visits: 36
|
|
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.
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Monday, April 29, 2013 10:15 AM
Points: 2,261,
Visits: 758
|
|
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
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Sunday, July 03, 2011 7:09 AM
Points: 258,
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
|
|
|
|