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.
The correct thing to do here is to store it as uniqueidentifier
- this is then fully indexable, etc. at the database. The next-best option would be a binary(16)
column: standard GUIDs are exactly 16 bytes in length.
If you must store it as a string, the length really comes down to how you choose to encode it. As hex (AKA base-16 encoding) without hyphens it would be 32 characters (two hex digits per byte), so char(32)
.
However, you might want to store the hyphens. If you are short on space, but your database doesn't support blobs / guids natively, you could use Base64 encoding and remove the ==
padding suffix; that gives you 22 characters, so char(22)
. There is no need to use Unicode, and no need for variable-length - so nvarchar(max)
would be a bad choice, for example.