NEWID (Transact-SQL)

A. Using the NEWID function with a variable

The following example uses NEWID() to assign a value to a variable declared as the uniqueidentifier data type. The value of the uniqueidentifier data type variable is printed before the value is tested.

The value returned by NEWID is different for each computer. This number is shown only for illustration.

B. Using NEWID in a CREATE TABLE statement

The following example creates the cust table with a uniqueidentifier data type, and uses NEWID to fill the table with a default value. In assigning the default value of NEWID(), each new and existing row has a unique value for the CustomerID column.