SQL Server NEWSEQUENTIALID() Function
NEWSEQUENTIALID() returns a value of type uniqueidentifier that is ordered after values previously generated by the function on the same computer since Windows started. It is intended for a DEFAULT constraint on a uniqueidentifier column, not as a function to call in a query.
Syntax
NEWSEQUENTIALID()
Use it as a column default
CREATE TABLE dbo.Orders (
OrderId uniqueidentifier NOT NULL
CONSTRAINT DF_Orders_OrderId DEFAULT NEWSEQUENTIALID(),
OrderName nvarchar(100) NOT NULL,
CONSTRAINT PK_Orders PRIMARY KEY CLUSTERED (OrderId)
);
INSERT INTO dbo.Orders (OrderName)
OUTPUT inserted.OrderId, inserted.OrderName
VALUES (N'Sample order');
Do not pass NEWSEQUENTIALID() as a value in an INSERT or SELECT, or wrap it in another scalar function. SQL Server permits it only in the default expression for a uniqueidentifier column.
NEWSEQUENTIALID() and NEWID()
Use NEWID() when a GUID can be generated directly in a query or statement. For a GUID column used as an index key, NEWSEQUENTIALID() can reduce random page activity and page splits compared with random GUIDs. Measure the impact for the actual workload; sequential GUIDs are larger than integer keys and may not be the right choice for every table.
Privacy and failover considerations
Do not use sequential GUIDs as password, session, or access tokens. Their values can be predictable, so exposing one may allow others to guess nearby identifiers. Microsoft also notes that the sequence can restart in a lower range after Windows restarts, and machine moves or failovers can create clusters in the generated values. Treat the GUID as a key, not as a secret or an exact timestamp.