Waldemar
Waldemar

Reputation: 5513

How does SQL Server generate Guids?

I've supposed that Guids should have completely random values, but I've found the following IDs generated by SQL Server in my table:

15B308E5-FC37-E711-9C42-185E0F1C3427
52B09CEE-FC37-E711-9C42-185E0F1C3427
BE9553FF-FC37-E711-9C42-185E0F1C3427
BF9553FF-FC37-E711-9C42-185E0F1C3427
CE169E05-FD37-E711-9C42-185E0F1C3427

They do not seem to be random enough for me :)

So I'm just wondering, how does SQL Server generate those values?

Thanks in advance!

Upvotes: 0

Views: 352

Answers (1)

Dan Guzman
Dan Guzman

Reputation: 46425

It looks like the GUIDs in your example were generated with a NEWSEQUENTIALID() default constraint. In that case, SQL Server uses the UuidCreateSequential Win32 API, along with some byte swapping to generate ordered GUID values that are sequential since the last computer restart.

Upvotes: 3

Related Questions