<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Database ID: Int vs. BigInt vs. GUID</title>
	<atom:link href="http://lostechies.com/derickbailey/2009/07/14/database-id-int-vs-bigint-vs-guid/feed/" rel="self" type="application/rss+xml" />
	<link>http://lostechies.com/derickbailey/2009/07/14/database-id-int-vs-bigint-vs-guid/</link>
	<description>Better Than Yesterday</description>
	<lastBuildDate>Mon, 20 May 2013 17:13:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.2</generator>
	<item>
		<title>By: Robinson</title>
		<link>http://lostechies.com/derickbailey/2009/07/14/database-id-int-vs-bigint-vs-guid/#comment-353</link>
		<dc:creator>Robinson</dc:creator>
		<pubDate>Thu, 13 Aug 2009 20:59:16 +0000</pubDate>
		<guid isPermaLink="false">/blogs/derickbailey/archive/2009/07/14/database-id-int-vs-bigint-vs-guid.aspx#comment-353</guid>
		<description>Joining this discussion a little late I know.  I thought about using an integer primary key and then also having a unique GUID (generated by the DB) for the purposes of replication, in each table too.  I&#039;m not sure how this would play out.  Any thoughts?</description>
		<content:encoded><![CDATA[<p>Joining this discussion a little late I know.  I thought about using an integer primary key and then also having a unique GUID (generated by the DB) for the purposes of replication, in each table too.  I&#8217;m not sure how this would play out.  Any thoughts?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bernhard Kircher</title>
		<link>http://lostechies.com/derickbailey/2009/07/14/database-id-int-vs-bigint-vs-guid/#comment-352</link>
		<dc:creator>Bernhard Kircher</dc:creator>
		<pubDate>Fri, 24 Jul 2009 06:48:44 +0000</pubDate>
		<guid isPermaLink="false">/blogs/derickbailey/archive/2009/07/14/database-id-int-vs-bigint-vs-guid.aspx#comment-352</guid>
		<description>@Randolpho: Can you explain why you loose the clustered index on the primary key, when using a Uniqueidentifier? Does this apply only to a specific Database engine or in general?

Thanks,
Bernhard Kircher</description>
		<content:encoded><![CDATA[<p>@Randolpho: Can you explain why you loose the clustered index on the primary key, when using a Uniqueidentifier? Does this apply only to a specific Database engine or in general?</p>
<p>Thanks,<br />
Bernhard Kircher</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Enrique Ramirez</title>
		<link>http://lostechies.com/derickbailey/2009/07/14/database-id-int-vs-bigint-vs-guid/#comment-351</link>
		<dc:creator>Enrique Ramirez</dc:creator>
		<pubDate>Wed, 22 Jul 2009 20:47:40 +0000</pubDate>
		<guid isPermaLink="false">/blogs/derickbailey/archive/2009/07/14/database-id-int-vs-bigint-vs-guid.aspx#comment-351</guid>
		<description>Ok so if I understand correctly, I&#039;d use a GUID to ensure that my object/entity is unique. But, as far as joining data together between tables, I&#039;d keep on using other keys/columns, etc?

I know seems like I&#039;m looking at the problem from the DB&#039;s perspective, and that if I&#039;m using an ORM I probably shouldn&#039;t even care about this. I just want to make sure I actually get all of this.</description>
		<content:encoded><![CDATA[<p>Ok so if I understand correctly, I&#8217;d use a GUID to ensure that my object/entity is unique. But, as far as joining data together between tables, I&#8217;d keep on using other keys/columns, etc?</p>
<p>I know seems like I&#8217;m looking at the problem from the DB&#8217;s perspective, and that if I&#8217;m using an ORM I probably shouldn&#8217;t even care about this. I just want to make sure I actually get all of this.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Randolpho</title>
		<link>http://lostechies.com/derickbailey/2009/07/14/database-id-int-vs-bigint-vs-guid/#comment-350</link>
		<dc:creator>Randolpho</dc:creator>
		<pubDate>Mon, 20 Jul 2009 15:39:52 +0000</pubDate>
		<guid isPermaLink="false">/blogs/derickbailey/archive/2009/07/14/database-id-int-vs-bigint-vs-guid.aspx#comment-350</guid>
		<description>I think there are valid reasons *not* to use GUIDs...  the biggest being the loss of a clustered index on your primary key, which can be a significant performance hit unless you spend a *lot* of time fine-tuning your DB. 

That said, from an architectural point of view, I vastly prefer GUIDs to IDENTs for my primary keys. I discount the most common argument against GUIDs, which is the whole &quot;what if I&#039;m trying to troubleshoot the DB and I have to type in this whole big nasty GUID rather than a simple WHERE ID=12345?&quot; argument. COPY AND PASTE, people! 

The people who say &quot;well, what about the ops folks being able to say &quot;that&#039;s an issue 144&#039;?&quot; I just want to smack upside the head. USE NATURAL KEYS, people!</description>
		<content:encoded><![CDATA[<p>I think there are valid reasons *not* to use GUIDs&#8230;  the biggest being the loss of a clustered index on your primary key, which can be a significant performance hit unless you spend a *lot* of time fine-tuning your DB. </p>
<p>That said, from an architectural point of view, I vastly prefer GUIDs to IDENTs for my primary keys. I discount the most common argument against GUIDs, which is the whole &#8220;what if I&#8217;m trying to troubleshoot the DB and I have to type in this whole big nasty GUID rather than a simple WHERE ID=12345?&#8221; argument. COPY AND PASTE, people! </p>
<p>The people who say &#8220;well, what about the ops folks being able to say &#8220;that&#8217;s an issue 144&#8242;?&#8221; I just want to smack upside the head. USE NATURAL KEYS, people!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: derick.bailey</title>
		<link>http://lostechies.com/derickbailey/2009/07/14/database-id-int-vs-bigint-vs-guid/#comment-349</link>
		<dc:creator>derick.bailey</dc:creator>
		<pubDate>Wed, 15 Jul 2009 21:42:11 +0000</pubDate>
		<guid isPermaLink="false">/blogs/derickbailey/archive/2009/07/14/database-id-int-vs-bigint-vs-guid.aspx#comment-349</guid>
		<description>(NOTE: adding this comment on behalf of Bernhard Kircher. He couldn&#039;t get the comment to post, for some reason, so he emailed it to me)

I just wanted to add some information on Guid generation within Code. As mentioned in the article on NHibernate, Guid.NewGuid() is not the best idea because of fragmentation, and therefore causing more IO and so on. The Guid.Comb seems to be a good idea (depending on it&#039;s implementation). I just wanted to add, that if you are using MS SQL server, you can generate the Guids in your code the same way the server does when calling newsequentialid(). It uses the rpcrt4.dll. The generated guid has to be edited, because of the way sql server is sorting them. I added more information here (with more links to my resources)
http://stackoverflow.com/questions/170346/what-are-the-performance-improvement-of-sequential-guid-over-standard-guid/1042719#1042719

best regards,
Bernhard Kircher </description>
		<content:encoded><![CDATA[<p>(NOTE: adding this comment on behalf of Bernhard Kircher. He couldn&#8217;t get the comment to post, for some reason, so he emailed it to me)</p>
<p>I just wanted to add some information on Guid generation within Code. As mentioned in the article on NHibernate, Guid.NewGuid() is not the best idea because of fragmentation, and therefore causing more IO and so on. The Guid.Comb seems to be a good idea (depending on it&#8217;s implementation). I just wanted to add, that if you are using MS SQL server, you can generate the Guids in your code the same way the server does when calling newsequentialid(). It uses the rpcrt4.dll. The generated guid has to be edited, because of the way sql server is sorting them. I added more information here (with more links to my resources)<br />
<a href="http://stackoverflow.com/questions/170346/what-are-the-performance-improvement-of-sequential-guid-over-standard-guid/1042719#1042719" rel="nofollow">http://stackoverflow.com/questions/170346/what-are-the-performance-improvement-of-sequential-guid-over-standard-guid/1042719#1042719</a></p>
<p>best regards,<br />
Bernhard Kircher </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eyston</title>
		<link>http://lostechies.com/derickbailey/2009/07/14/database-id-int-vs-bigint-vs-guid/#comment-348</link>
		<dc:creator>Eyston</dc:creator>
		<pubDate>Wed, 15 Jul 2009 20:51:43 +0000</pubDate>
		<guid isPermaLink="false">/blogs/derickbailey/archive/2009/07/14/database-id-int-vs-bigint-vs-guid.aspx#comment-348</guid>
		<description>@Dan

Thanks for reply.

That makes a lot of sense (the OrderCodeGenerator).  I guess  I was blinded to the idea that the hi-lo is an algorithm, not just an option in NHibernate :)

So that OrderCodeGenerator would not only abstract away the process but if it implemented the hi-lo algorithm would remove the database lookup per order creation (although it definitely could have a db request if done lazily on the first one, or if it ran out of lo&#039;s, etc).

I dream about one day not having my crappy db, and that was the latest thing on my mind of &quot;how would I do that&quot; :)</description>
		<content:encoded><![CDATA[<p>@Dan</p>
<p>Thanks for reply.</p>
<p>That makes a lot of sense (the OrderCodeGenerator).  I guess  I was blinded to the idea that the hi-lo is an algorithm, not just an option in NHibernate :)</p>
<p>So that OrderCodeGenerator would not only abstract away the process but if it implemented the hi-lo algorithm would remove the database lookup per order creation (although it definitely could have a db request if done lazily on the first one, or if it ran out of lo&#8217;s, etc).</p>
<p>I dream about one day not having my crappy db, and that was the latest thing on my mind of &#8220;how would I do that&#8221; :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dan Malcolm</title>
		<link>http://lostechies.com/derickbailey/2009/07/14/database-id-int-vs-bigint-vs-guid/#comment-347</link>
		<dc:creator>Dan Malcolm</dc:creator>
		<pubDate>Wed, 15 Jul 2009 20:25:34 +0000</pubDate>
		<guid isPermaLink="false">/blogs/derickbailey/archive/2009/07/14/database-id-int-vs-bigint-vs-guid.aspx#comment-347</guid>
		<description>@Eyston

Assigning a human-friendly identifier to entities (&quot;order number&quot;, &quot;customer number&quot; etc) is a separate business requirement and doesn&#039;t have to inform or conflict with your choice of PK data type. Bear in mind the requirement could easily extend to something other than a sequential integer, e.g. some kind of &quot;meaningful&quot; prefix.

This requirement isn&#039;t that awkward to implement. You have some kind of strategy - IOrderCodeGenerator.Assign(Order order) or something - to generate the codes. A database will have to come into play to generate the sequence, but the hi-lo algorithm &quot;reserves&quot; a number of keys in a sequence within a single database call. This approach won&#039;t interfere with batching at the ORM level.</description>
		<content:encoded><![CDATA[<p>@Eyston</p>
<p>Assigning a human-friendly identifier to entities (&#8220;order number&#8221;, &#8220;customer number&#8221; etc) is a separate business requirement and doesn&#8217;t have to inform or conflict with your choice of PK data type. Bear in mind the requirement could easily extend to something other than a sequential integer, e.g. some kind of &#8220;meaningful&#8221; prefix.</p>
<p>This requirement isn&#8217;t that awkward to implement. You have some kind of strategy &#8211; IOrderCodeGenerator.Assign(Order order) or something &#8211; to generate the codes. A database will have to come into play to generate the sequence, but the hi-lo algorithm &#8220;reserves&#8221; a number of keys in a sequence within a single database call. This approach won&#8217;t interfere with batching at the ORM level.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eyston</title>
		<link>http://lostechies.com/derickbailey/2009/07/14/database-id-int-vs-bigint-vs-guid/#comment-346</link>
		<dc:creator>Eyston</dc:creator>
		<pubDate>Wed, 15 Jul 2009 14:57:00 +0000</pubDate>
		<guid isPermaLink="false">/blogs/derickbailey/archive/2009/07/14/database-id-int-vs-bigint-vs-guid.aspx#comment-346</guid>
		<description>Also, I&#039;m not 100% sure I would qualify order # as natural key:  it has absolutely no business meaning other than as a unique identifier and no one ever keys it in.  Maybe that still makes it a  natural key, I dunno.

We have some tables at work that deal with parts.  A part number is the key of that table.  This has caused a ton of problems.  The thing that makes it suck is (a) users actually key this in and (b) a part number has a ton of meaning outside of the database.  The part number, once entered and used, no matter how wrong or how many good reasons there are to change it, can no longer be changed without breaking all FK relationships.  It sucks.

What sucks even more is that natural key such as this (part number) just lead to composite key (serial number?  oh that is unique per part .... so serial table is PK of serial # and part #... ugh).

Sorry for just thinking out loud here -- it is just that at first glance it is absolutely clear to me that guid.comb is wonderful... decision done, one less thing to worry about, check mark!  But now I am doubting or questioning at least.</description>
		<content:encoded><![CDATA[<p>Also, I&#8217;m not 100% sure I would qualify order # as natural key:  it has absolutely no business meaning other than as a unique identifier and no one ever keys it in.  Maybe that still makes it a  natural key, I dunno.</p>
<p>We have some tables at work that deal with parts.  A part number is the key of that table.  This has caused a ton of problems.  The thing that makes it suck is (a) users actually key this in and (b) a part number has a ton of meaning outside of the database.  The part number, once entered and used, no matter how wrong or how many good reasons there are to change it, can no longer be changed without breaking all FK relationships.  It sucks.</p>
<p>What sucks even more is that natural key such as this (part number) just lead to composite key (serial number?  oh that is unique per part &#8230;. so serial table is PK of serial # and part #&#8230; ugh).</p>
<p>Sorry for just thinking out loud here &#8212; it is just that at first glance it is absolutely clear to me that guid.comb is wonderful&#8230; decision done, one less thing to worry about, check mark!  But now I am doubting or questioning at least.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eyston</title>
		<link>http://lostechies.com/derickbailey/2009/07/14/database-id-int-vs-bigint-vs-guid/#comment-345</link>
		<dc:creator>Eyston</dc:creator>
		<pubDate>Wed, 15 Jul 2009 14:44:34 +0000</pubDate>
		<guid isPermaLink="false">/blogs/derickbailey/archive/2009/07/14/database-id-int-vs-bigint-vs-guid.aspx#comment-345</guid>
		<description>@Derick

I totally agree with the first half -- I&#039;m not saying Order 1097820 should be the PK.  I want a guid PK, but I want to keep a unique number to be able to reference it by for humans.  Like you say a unique constraint on that column in db.

What sucks is that the benefits of a GUID (or any generated id) is that the ORM can generate the field and save round trips and allow batching.  BUT when I now want a seperate unique key as an integer for humans, I have no idea how to generate that WITHOUT somehow working with the database (I&#039;m not saying its impossible, just I have no idea how to do it).

I am wondering if any tips/tricks exist for this:  how to generate a unique (non-PK) key for an entity w/out requiring that extra database trip to either (a) generate the key or (b) verify that it truly is unique.</description>
		<content:encoded><![CDATA[<p>@Derick</p>
<p>I totally agree with the first half &#8212; I&#8217;m not saying Order 1097820 should be the PK.  I want a guid PK, but I want to keep a unique number to be able to reference it by for humans.  Like you say a unique constraint on that column in db.</p>
<p>What sucks is that the benefits of a GUID (or any generated id) is that the ORM can generate the field and save round trips and allow batching.  BUT when I now want a seperate unique key as an integer for humans, I have no idea how to generate that WITHOUT somehow working with the database (I&#8217;m not saying its impossible, just I have no idea how to do it).</p>
<p>I am wondering if any tips/tricks exist for this:  how to generate a unique (non-PK) key for an entity w/out requiring that extra database trip to either (a) generate the key or (b) verify that it truly is unique.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: derick.bailey</title>
		<link>http://lostechies.com/derickbailey/2009/07/14/database-id-int-vs-bigint-vs-guid/#comment-344</link>
		<dc:creator>derick.bailey</dc:creator>
		<pubDate>Wed, 15 Jul 2009 14:01:31 +0000</pubDate>
		<guid isPermaLink="false">/blogs/derickbailey/archive/2009/07/14/database-id-int-vs-bigint-vs-guid.aspx#comment-344</guid>
		<description>All,

a coworker responded via company email. i thought his response was worth sharing. you can read it here:

http://www.lostechies.com/blogs/derickbailey/archive/2009/07/15/storage-size-and-performance-implications-of-a-guid-pk.aspx
</description>
		<content:encoded><![CDATA[<p>All,</p>
<p>a coworker responded via company email. i thought his response was worth sharing. you can read it here:</p>
<p><a href="http://www.lostechies.com/blogs/derickbailey/archive/2009/07/15/storage-size-and-performance-implications-of-a-guid-pk.aspx" rel="nofollow">http://www.lostechies.com/blogs/derickbailey/archive/2009/07/15/storage-size-and-performance-implications-of-a-guid-pk.aspx</a></p>
]]></content:encoded>
	</item>
</channel>
</rss>
