Skip to content

Latest commit

 

History

History
76 lines (56 loc) · 3.47 KB

File metadata and controls

76 lines (56 loc) · 3.47 KB
title NEWSEQUENTIALID (Transact-SQL) | Microsoft Docs
ms.custom
ms.date 08/08/2015
ms.prod sql-non-specified
ms.reviewer
ms.suite
ms.technology
database-engine
ms.tgt_pltfrm
ms.topic language-reference
f1_keywords
NEWSEQUENTIALID
NEWSEQUENTIALID_TSQL
dev_langs
TSQL
helpviewer_keywords
NEWSEQUENTIALID function
GUIDs [SQL Server]
ms.assetid e06d2cab-f1ff-42f1-8550-6aaec57be36f
caps.latest.revision 33
author BYHAM
ms.author rickbyh
manager jhubbard

NEWSEQUENTIALID (Transact-SQL)

[!INCLUDEtsql-appliesto-ss2008-asdb-xxxx-xxx_md]

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. When a GUID column is used as a row identifier, using NEWSEQUENTIALID can be faster than using the NEWID function. This is because the NEWID function causes random activity and uses fewer cached data pages. Using NEWSEQUENTIALID also helps to completely fill the data and index pages.

Important

If privacy is a concern, do not use this function. It is possible to guess the value of the next generated GUID and, therefore, access data associated with that GUID.

NEWSEQUENTIALID is a wrapper over the Windows UuidCreateSequential function.

Warning

The UuidCreateSequential function has hardware dependencies. On [!INCLUDEssNoVersion], clusters of sequential values can develop when databases (such as contained databases) are moved to other computers. When using Always On and on [!INCLUDEsqldbesa], clusters of sequential values can develop if the database fails over to a different computer.

Topic link icon Transact-SQL Syntax Conventions

Syntax

  
NEWSEQUENTIALID ( )  

Return Type

uniqueidentifier

Remarks

NEWSEQUENTIALID() can only be used with DEFAULT constraints on table columns of type uniqueidentifier. For example:

CREATE TABLE myTable (ColumnA uniqueidentifier DEFAULT NEWSEQUENTIALID());   

When NEWSEQUENTIALID() is used in DEFAULT expressions, it cannot be combined with other scalar operators. For example, you cannot execute the following:

CREATE TABLE myTable (ColumnA uniqueidentifier DEFAULT dbo.myfunction(NEWSEQUENTIALID()));  

In the previous example, myfunction() is a scalar user-defined scalar function that accepts and returns a uniqueidentifier value.

NEWSEQUENTIALID cannot be referenced in queries.

You can use NEWSEQUENTIALID to generate GUIDs to reduce page splits and random IO at the leaf level of indexes.

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.

See Also

NEWID (Transact-SQL)
Comparison Operators (Transact-SQL)