Mitesh Patel

Mitesh Patel

  • 1.5k
  • 188
  • 136.6k

NEWID() vs NEWSEQUENTIALID()

Aug 3 2018 12:43 PM
NEWID() generates the GUID in random order .
 
NEWSEQUENTIALID() which generates the GUID in sequential order.
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.
 
 
CREATE TABLE SeQGUID_Example
(
SeqColumn uniqueidentifier DEFAULT NewSequentialID()
,IDColumn uniqueidentifier DEFAULT NEWID(),)
----Inserting five default values in table
INSERT INTO SeQGUID_Example DEFAULT
VALUES
INSERT INTO SeQGUID_Example DEFAULT
VALUES
INSERT INTO SeQGUID_Example DEFAULT
VALUES
INSERT INTO SeQGUID_Example DEFAULT
VALUES
---------------------------------------------------------
SELECT *
FROM SeQGUID_Example
----Clean up database
DROP TABLE SeQGUID_Example

Answers (1)