In SQL Server, you can use the NEWSEQUENTIALID()
function to create incremental unique values.
It creates a GUID (Globally Unique IDentifier) that is greater than any GUID previously generated by this function on a specified computer since the operating system was started. After restarting the operating system, the GUID can start again from a lower range, but is still globally unique.
The NEWSEQUENTIALID()
function can only be used with DEFAULT
constraints on table columns of type uniqueidentifier. Therefore, you can’t just run a query like SELECT NEWSEQUENTIALID()
and expect it to work (but you can do that with the NEWID()
function).
Continue reading →