NEWID function [Miscellaneous]

Function

Generates a UUID (Universally Unique Identifier) value. 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 updates the table mytab and sets 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.

UPDATE mytab
    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 cannot use the NEWID function as a column default for a Sybase IQ table.

Standards and compatibility

See also

“STRTOUUID function [String]”

“UUIDTOSTR function [String]”

UNIQUEIDENTIFIER in “Binary data types”

UNIQUEIDENTIFIERSTR in Character data types