Transact-SQL Reference


SQL Server 2005 Books Online (November 2008)
NEWSEQUENTIALID()

Updated: 14 April 2006

Creates a GUID that is greater than any GUID previously generated by this function on a specified computer.

ms189786.note(en-US,SQL.90).gifImportant:
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.

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.

The GUIDs generated by NEWSEQUENTIALID() are unique only within a particular computer if the computer does not have a network card.

You can use NEWSEQUENTIALID() to generate GUIDs to reduce page contention at the leaf level of indexes.

See Also

Reference

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

Help and Information

Getting SQL Server 2005 Assistance
Change History

Release History

14 April 2006

Changed content:
  • Modified the statement about GUID uniqueness.
Tags :


Community Content

Jeff Fischer
SQL Server unique identifier solution

Refer to my blog for best practices on using uniqueidentifier sql server 2005.

Jeff Fischer

Tags :

Page view tracker