Question

In SQL Server, what is the probability of creating tow GUIDs with the same value with this code?

DECLARE @EmployeeID UNIQUEIDENTIFIER;
SET @EmployeeID = NEWID();
Was it helpful?

Solution

Basically a GUID is a 128-bit number, with 6 informational bits and 122 random ones. So the probability is 1/(2122), where 2122 = 5.31 * 1036.

Here is a citation from my other answer:

According to this document (RFC 4122) and comparing with GUIDs generated by C#, they are of random type.

This type has the following pattern: xxxxxxxx-xxxx-4xxx-Vxxx-xxxxxxxxxxxx, where

  • x is random number and
  • V is a number with bit layout as 10yy, where yy are two random bits.

So, here we have 122 random bits out of 128.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top