NEWID function [Miscellaneous]

Function

Generates a UUID (Universally Unique Identifier) value. The returned UUID value is a binary. A UUID is the same as a GUID (Globally Unique Identifier).

Syntax

NEWID ( )

Parameters

There are no parameters associated with NEWID().

Example

The following statement creates the table t1 and then updates the table, setting the value of the column uid_col to a unique identifier generated by the NEWID function, if the current value of the column is NULL.

CREATE TABLE t1 (uid_col int);
UPDATE t1
    SET uid_col = NEWID()
      WHERE uid_col IS NULL

If you execute the following statement,

SELECT NEWID()

the unique identifier is returned as a BINARY(16). For example, the value might be 0xd3749fe09cf446e399913bc6434f1f08. You can convert this string into a readable format using the UUIDTOSTR() function.

Usage

The NEWID() function generates a unique identifier value.

UUIDs can be used to uniquely identify objects in a database. The values are generated such that a value produced on one computer does not match that produced on another, hence they can also be used as keys in replication and synchronization environments.

The NEWID function is supported only in the following positions:

You can use a value generated by the NEWID function as a column default value in a Sybase IQ table.

Standards and compatibility

See also

“STRTOUUID function [String]”

“UUIDTOSTR function [String]”

“Binary data types”

“Character data types”