.netguidvarcharsql-typesstring-length

What is the string length of a GUID?


I want to create a varchar column in SQL that should contain N'guid' while guid is a generated GUID by .NET (Guid.NewGuid) - class System.Guid.

What is the length of the varchar I should expect from a GUID? Is it a static length?

Should I use nvarchar (will GUID ever use Unicode characters)?

varchar(Guid.Length)

PS. I don't want to use a SQL row guid data-type. I am just asking what is Guid.MaxLength.


Solution

  • It depends on how you format the Guid:

    It is possible to represent a Guids 16 bytes as a shorter string than shown above, but to do this you'd need to use an alternative formatter to the built in ToString() function.