SQL Server – NEWID () vs. NEWSEQUENTIALID ()

NEWID ()

NEWID () creates a unique value of type uniqueidentifier.

  • NEWID () can be referenced in the queries.

Example:

01 SQL Server - NEWID () vs. NEWSEQUENTIALID ()

01 SQL Server – NEWID () vs. NEWSEQUENTIALID ()

NEWSEQUENTIALID ()

NEWSEQUENTIALID () creates a GUID that is greater than any GUID previously generated by this function on a specified computer since Windows was started. After restarting Windows, the GUID can start again from a lower range, but is still globally unique.

  • NEWSEQUENTIALID () cannot be referenced in queries.

Example:

02 SQL Server - NEWID () vs. NEWSEQUENTIALID ()

02 SQL Server – NEWID () vs. NEWSEQUENTIALID ()

Example:

Using table

03 SQL Server - NEWID () vs. NEWSEQUENTIALID ()

03 SQL Server – NEWID () vs. NEWSEQUENTIALID ()

Imp Note:

  • Each GUID generated by using NEWSEQUENTIALID () is unique on that computer. GUIDs generated by using NEWSEQUENTIALID () are unique across multiple computers only if the source computer has a network card.
  • When a GUID column is used as a row identifier, using NEWSEQUENTIALID can be faster than using the NEWID function.