Contents Index MONTHS function [Date and time] NEXT_CONNECTION function [System]

ASA SQL Reference
  SQL Functions
    Alphabetical list of functions

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().

Usage 

The NEWID() function generates a unique identifier value. It can be used in a DEFAULT clause for a column.

UUIDs can be used to uniquely identify rows in a table. The values are generated such that a value produced on one computer will not match that produced on another. Hence they can also be used as keys in replication and synchronization environments.

NEWID is a non-deterministic function. Successive calls to NEWID may return different values. The query optimizer does not cache the results of the NEWID function.

For more information about non-deterministic functions, see Function caching.

Standards and compatibility 
See also 

The NEWID default

STRTOUUID function [STRING]

UUIDTOSTR function [STRING]

UNIQUEIDENTIFIER data type [Binary]

Example 

The following statement creates a table mytab with two columns. Column pk has a unique identifier data type, and assigns the newid() function as the default value. Column c1 has an integer data type.

CREATE TABLE mytab( pk uniqueidentifier primary key default newid(), c1 int )

If you execute the following statement,

SELECT newid()

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


Contents Index MONTHS function [Date and time] NEXT_CONNECTION function [System]