0

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

DECLARE @EmployeeID UNIQUEIDENTIFIER;
SET @EmployeeID = NEWID();
p.s.w.g
  • 146,324
  • 30
  • 291
  • 331
miguelbgouveia
  • 2,963
  • 6
  • 29
  • 48

1 Answers1

2

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.

Community
  • 1
  • 1
Artemix
  • 2,113
  • 2
  • 23
  • 34