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
  • 141,205
  • 29
  • 278
  • 318
miguelbgouveia
  • 2,901
  • 5
  • 27
  • 46

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,063
  • 2
  • 23
  • 33