views:

608

answers:

2

I know that primary keys based on Guids do not have the best performance (due to the fragmentation), but they are globally unique and allow replication scenarios.

Integral identifiers, on the other side, have greater performance at the cost of scalability.

But in what scenarios would someone want to use sequential uniqueidentifier as the primary key? I think, that it beats the purpose of GUID, but still I see mentioning of the sequentals now and then.

What do I miss here?

+6  A: 

What is commonly known as a sequential guids in SQL Server 2005 (generated by NEWSEQUENTIALID()) are an attempt to overcome the issues with normal guids.

They are still universally unique but also are always ascending. This means that they can be used for replication and have much better insert performance than traditional GUIDs.

The one drawback is that they are not "secure" because it is possible to guess the next sequential guid.

http://msdn.microsoft.com/en-us/library/ms189786.aspx

Mike
Just a small point. They are almost certainly unique universally. They are unique on a specific computer. If a machine does not have a network card they can become non-unique (though this scenario is very unlikely for a SQL Server).
BlackWasp
+1  A: 

Using sequential guids ensures that you are always using a value larger than the last value. For an indexed field this is important. Instead of inserting randomly all over the spectrum, you are always inserting at the end of the last "page" of data, resulting in drastically reduced page splits, especially in the case where your uniqueidentifier column is also your clustered index.

Mel