Newid() vs Newsequentialid() – Performance Of, Differences Between and Examples

This article helps to explain the key differences between Newid() and Newsequentialid(). (crucial info if you are sitting the 70-461 SQL exam)

Quick Answer

NEWID() generates the GUID in random order vs NEWSEQUENTIALID() which generates the GUID in sequential order.

Key Facts

  • Newsequentialid() creates a GUID greater than the previous one, since windows was started. If windows has been restarted the GUID may begin at a lower range (still unique however).
  • For best performance of inserts use newsequentialid().
  • NEWSEQUENTIALID is able to completely fill data and index pages.
  • Newid() you can use in a select, newsequentialid() you cant
  • If you are worried about, or have a need for privacy don’t use sequential GUIDs
  • NEWID() is RFC4122 compliant.

Newid() vs Newsequentialid() T-SQL Example


USE dbafire_db;
GO
----Create Test Table for with default columns values
CREATE TABLE GUID_Example
(
SeqCol uniqueidentifier DEFAULT NewSequentialID()
,IDCol uniqueidentifier DEFAULT NEWID(),)
----Inserting five default values in table
INSERT INTO GUID_Example DEFAULT
VALUES
INSERT INTO GUID_Example DEFAULT
VALUES
INSERT INTO GUID_Example DEFAULT
VALUES
INSERT INTO GUID_Example DEFAULT
VALUES
---------------------------------------------------------
SELECT *
FROM GUID_Example

----Clean up database 

DROP TABLE GUID_Example



Result Output

Note how easy it would have been to guess the sequentialid value (blue box).

sequentialid vs newid

In this article we have shown you what the differences are between the two GUID functions.

Is there anything you think we should add, or that you have experienced with either Newid() or Newsequentialid()?

Rob StGeorge
Senior SQL Server Database Administrator residing in Auckland, NZ

1 Comment

  1. trying to figure out the best unique id mechanism to use for distributed databases which are also performant. any information on that would be greatly appreciated. thanks.

Leave a Reply