Uniqueidentifier (T-SQL)

UniqueIdentifier is a 16-byte GUID. The uniqueidentifier type is limited to 36 characters, the characters that exceed that length are truncated

A column or local variable of uniqueidentifier data type can be initialized to a value in the following ways:

  • By using the NEWID function.
  • By converting from a string constant in the form xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx, in which each x is a hexadecimal digit in the range 0-9 or a-f. For example, 6F9619FF-8B86-D011-B42D-00C04FC964FF is a valid uniqueidentifier value.
DECLARE @uniqueID uniqueidentifier = NEWID();
SELECT CONVERT(char(255), @uniqueID);