NEWGUID
The NEWGUID
function is used to create a new globally unique identifier (GUID). It can be used to generate a new GUID whenever one is needed.
The function has three different syntax options:
The first option, NEWGUID(), generates a new GUID with a random value.
The second option, NEWGUID(int value), generates a new GUID with the specified integer value as the seed. This can be useful for generating a reproducible sequence of GUIDs.
The third option, NEWGUID(Guid? g, int value), generates a new GUID based on a provided GUID and integer seed value. This can be useful for generating a new GUID that is related to an existing GUID.
The function returns a new Guid value each time it is called.
Syntax
Guid NEWGUID()
Guid NEWGUID(int value)
Guid NEWGUID(Guid? g, int value)
Example
NEWGUID(12)
Returns '0000000c-0000-0000-0000-000000000000'.
NEWGUID(NEWGUID(), 12)
Returns a new guid such as '0000000c-741d-4dc4-a924-0bde522f7718'.
NEWGUID()
In this example, the function is used to generate a new GUID with a random value. The function returns a new Guid value each time it is called, providing a unique identifier that can be used for various purposes, such as identifying records in a database.
You can pass in any integer columns into the NEWGUID function to crate a GUID based upon that value. For example you might want a GUID for different Product ID's, where the product id is an integer value and each row is unique:
NEWGUID(ProductID)