How SQL Server creates a uniqueidentifier using NEWID ()

I have a user_info table in five different places. Now I need to integrate all the rows into the central user_info table. To do this, I need a unique identifier for each row in the source tables. Because when all rows are in the central table, each user must have a unique identifier.

Now my questions are:

  • if I use uniqueidentifier NEWID() for each source table, will it be unique for global and life time or can it be duplicated?

  • How does SQL Server create NEWID() ? I need to know the key generation structure.

+6
source share
1 answer

Yes, there is no possibility of duplication between machines.

NEWID() based on a combination of a pseudo-random number (with clock) and the MAC address of the primary network card.

However, inserting random numbers like this, like a clustered key in a table, is terrible for performance. You should consider either the NEWSEQUENTIALID() function or a COMB function for generating GUIDs that still offer the NEWID() collision avoidance NEWID() while maintaining acceptable INSERT performance.

+7
source

Source: https://habr.com/ru/post/926036/


All Articles