As per microsoft documentation on UniqueIdentifier, This value is always a unique globally beacuse it's based on network clock and CPU clock time and on the other hand the same documentation says
uniqueidentifier columns may contain multiple occurrences of an
individual uniqueidentifier value, unless the UNIQUE or PRIMARY KEY
constraints are also specified for the column.
I'm not able to come to a conclusion how UniqueIdentifier (GUIDs) can be unique globally, as Network address (Mac address) can be same on two different networks, How GUIDs can be unique globally with which combinations and also why Microsoft says there should be primary or unique constraint in order to ensure we've unique UniqueIdeitifer value always.
https://technet.microsoft.com/en-us/library/ms190215(v=sql.105).aspx
Best Answer
Problem #1
The main problem here is that you are confusing two different things as being two terms that refer to one thing: UNIQUEIDENTIFIER and GUIDs.
UNIQUEIDENTIFIER
is a datatype. Datatypes define the nature of the data that they (i.e. columns and variables of this type) can contain (e.g. min / max values, etc) and certain behaviors of the data (e.g. how to handle comparisons). This particular datatype merely holds GUID / UUID values. But it is not data, so the concept of uniqueness does not apply to it. And the word "Unique" in the name "UniqueIdentifier" is not a promise, or even statement, regarding actual uniqueness.GUIDs / UUIDs are actual values that can be stored as
UNIQUEIDENTIFIER
, but could also be stored asVARBINARY
/BINARY
,(N)VARCHAR
/(N)CHAR
, and maybe some others. While theUNIQUEIDENTIFIER
datatype is the best choice (in SQL Server) for storing these values, storing the values in the other types does not make the values any more or less unique.Problem #2
The second problem here is that you are accepting, as fact, a technical error in the documentation that you linked to. I assume you are referring to this statement:
That statement is referring to functions like
NEWID()
in T-SQL andGuid.NewGuid()
in .NET that create new GUID / UUID values, and the intention of them to always generate unique values. However, that is not reality: newly generated GUIDs are not guaranteed to be unique. As you already pointed out, MAC Addresses aren't necessarily unique (they can even be spoofed; more info in the "Related info" section below). Also, from other Microsoft documentation:MSDN page for .NET Guid Structure states (emphasis added):
The .NET Guid.NewGuid() method (which is used to generate new GUID / UUID values) calls Win32Native.CoCreateGuid. The documentation for that function states (emphasis added):
Please note that the non-SQL Server documentation doesn't even mention MAC Address. And the documentation for
CoCreateGuid
points to the real function that does the generation: UuidCreate. The documentation for that function states:The implication here is that MAC Address is specifically not used (unless using
NEWSEQUENTIALID()
). And in fact, generating a few GUIDs in SQL Server viaNEWID()
indicates that they are RFC 4122, Version 4 UUIDs, which are extremely likely to be unique. There is a chart here, Random UUID probability of duplicates, that shows just how unlikely it is to have duplicates. However, even a very, very low probability of duplicates is not a guarantee of uniqueness.And so...
There is no guarantee that newly generated GUID / UUID values are unique. And, even if there was a guarantee, the
UNIQUEIDENTIFIER
datatype would still have nothing to do with actual uniqueness (as is shown in Brent's answer). Uniqueness, for one or more columns (i.e. data, not datatypes) can only be enforced by Unique Indexes / Constraints.Related info: