Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 10.0.1 » SQL Anywhere Server - SQL Reference » SQL Functions » Alphabetical list of functions

NCHAR function [String] Next Page

NEWID function [Miscellaneous]


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 the NEWID function.

Remarks

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 synchronization and replication environments.

UUIDs contain hyphens by default for compatibility with other RDBMSs. You change this by setting the uuid_has_hyphens option to Off.

For more information, see uuid_has_hyphens option [database].

The NEWID function is non-deterministic; successive calls 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.

See also
Standards and compatibility
Example

The following statement creates a table named 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 );

The following statement returns a unique identifier as a string:

SELECT NEWID();

For example, the value returned might be 96603324-6FF6-49DE-BF7D-F44C1C7E6856.