Click here to Skip to main content
15,895,084 members
Home / Discussions / Database
   

Database

 
GeneralImceda SQL IDE Pin
Derec Roofie13-Apr-08 0:58
Derec Roofie13-Apr-08 0:58 
GeneralRe: Imceda SQL IDE Pin
Pete O'Hanlon13-Apr-08 10:17
mvePete O'Hanlon13-Apr-08 10:17 
GeneralUrgent!! Pin
dheka12-Apr-08 2:13
dheka12-Apr-08 2:13 
GeneralRe: Urgent!! Pin
Mycroft Holmes13-Apr-08 15:32
professionalMycroft Holmes13-Apr-08 15:32 
GeneralRe: Urgent!! Pin
DerekFL14-Apr-08 4:04
DerekFL14-Apr-08 4:04 
GeneralIdentity Field Overuse vs. Bad Primary Keys Pin
ClarenceJr11-Apr-08 5:38
ClarenceJr11-Apr-08 5:38 
GeneralRe: Identity Field Overuse vs. Bad Primary Keys Pin
Michael Potter11-Apr-08 5:56
Michael Potter11-Apr-08 5:56 
GeneralRe: Identity Field Overuse vs. Bad Primary Keys Pin
Mark J. Miller11-Apr-08 9:34
Mark J. Miller11-Apr-08 9:34 
Another issue caused by using natural keys instead of surrogates (identities) is index fragmentation. Because identities are sequential there are less page splits required for inserts on clustered indexes (as well as other indexes). When you use a sequential identity the new record is appended to the "end" of the index. This certainly still causes page splits when the leaf nodes must balance the tree, but compare this to when you use a natural key the values you are inserting are almost always being inserted somewhere in the middle of a range of leaf nodes.

If your natural key is used a foreign key and you need to insert a large number of child records, then you're inserting a large number of records right in the middle of your index. Causing more fragmentation.

As your database grows in size this will increase the amount of maintenance your indexes will require to constantly rebuild and defragment them to maintain performance.

That brings us to read performance. With a surrogate key the data you need most often is physically adjacent. Think of reporting on orders or events which all occured w/in a specified time period. Yes you could use a clustered index on a date column, but that means 8 bytes of storage for each entry before you get to the leaf nodes - twice what's required for an INT. But with a natural key your data would be all over the map. Disk I/O is the worst bottleneck in your entire system. Imagine how much more work the disk heads need to work when the data is randomly placed, compared with scanning data in adjacent sectors.

You can use more padding on your indexes to reduce fragmentation and increase performance for modifications but this increases the I/O required to read your index on top of the fact that the natural key has already increased the size of your index in the first place.

And that is just the performance reasons for using surrogate keys. There are other arguments against natural keys.

In case you hadn't guessed, I don't think natural keys should ever be used - with one small exception. If we're talking about a very small set of possible keys which are tied to some sort of lookup data. The reason for this exception is that they are the exception to the performance problems cited above. Additionally, by using natural keys for a small dataset you can often store only the key in the child tables and use some sort of enumeration in your application code. This means you'll have less overhead because you won't have to maintain tables for all the different lookup types in your application.

Hope this helps your delimma. Of course you will need to decide what works best for your requirements and weight them to determine what the most important factors are in developing your application.

Mark's blog: developMENTALmadness.blogspot.com

Funniest variable name:
lLongDong - spotted in legacy code, was used to determine how long a beep should be.
- Dave Bacher

GeneralRe: Identity Field Overuse vs. Bad Primary Keys Pin
GuyThiebaut11-Apr-08 11:50
professionalGuyThiebaut11-Apr-08 11:50 
QuestionWhat is the default format of a calender in Visual Studio 2008? Pin
Daniel_Logan11-Apr-08 4:21
Daniel_Logan11-Apr-08 4:21 
AnswerRe: What is the default format of a calender in Visual Studio 2008? Pin
Ashfield11-Apr-08 4:41
Ashfield11-Apr-08 4:41 
GeneralRe: What is the default format of a calender in Visual Studio 2008? Pin
Daniel_Logan14-Apr-08 20:37
Daniel_Logan14-Apr-08 20:37 
AnswerRe: What is the default format of a calender in Visual Studio 2008? Pin
GuyThiebaut11-Apr-08 11:37
professionalGuyThiebaut11-Apr-08 11:37 
GeneralRe: What is the default format of a calender in Visual Studio 2008? Pin
Daniel_Logan14-Apr-08 20:54
Daniel_Logan14-Apr-08 20:54 
Questionxquery problem. Pin
blowout3311-Apr-08 4:01
blowout3311-Apr-08 4:01 
GeneralRe: xquery problem. Pin
Mark J. Miller11-Apr-08 9:55
Mark J. Miller11-Apr-08 9:55 
AnswerRe: xquery problem. Pin
blowout3314-Apr-08 1:10
blowout3314-Apr-08 1:10 
GeneralMigrating a FoxPro database to SQL Server 2005 Pin
Aptiva Dave11-Apr-08 3:34
Aptiva Dave11-Apr-08 3:34 
GeneralRe: Migrating a FoxPro database to SQL Server 2005 Pin
A Wong11-Apr-08 5:28
A Wong11-Apr-08 5:28 
QuestionHow to take table record from oracle into an arrays or RecordSet or DataTable, which to be bind to DropDownList? [modified] Pin
vishalcodeproj11-Apr-08 2:46
vishalcodeproj11-Apr-08 2:46 
QuestionHow to display image stored in SQL server into a control Pin
Jeevamohan11-Apr-08 1:23
Jeevamohan11-Apr-08 1:23 
GeneralRe: How to display image stored in SQL server into a control Pin
Pete O'Hanlon11-Apr-08 3:18
mvePete O'Hanlon11-Apr-08 3:18 
Questionmdb file is not opening Pin
gayatrilaxmi10-Apr-08 22:51
gayatrilaxmi10-Apr-08 22:51 
GeneralRe: mdb file is not opening Pin
John_Adams10-Apr-08 23:25
John_Adams10-Apr-08 23:25 
GeneralRe: mdb file is not opening Pin
gayatrilaxmi11-Apr-08 0:31
gayatrilaxmi11-Apr-08 0:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.