Back-To-School Deals - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Default values
How to auto-generate values in a database
12. NEWID()—explanation
Summary

Instruction

Nicely done! IDENTITY is not the only way to generate unique values; we also have the NEWID() function. Look at the example below:

SELECT NEWID();

You can use this function in the SELECT statement to get a unique, auto-generated value. NEWID doesn't take any arguments and returns only uniqueidentifier data. The uniqueidentifier data type is a global unique identifier (GUID), which is a long string, that looks something like this:

86E82700-7C7B-4256-950E-8423C0E32977

Each invocation of the NEWID() function generates a new, different GUID.

Exercise

Run a query that generates a GUID using the NEWID() function.