views:

9153

answers:

2

I want to create a varchar folumn in SQL should contain N'guid' while guid is a generated Guid by .net (Guid.NewGuid).

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 chars)?

varchar(Guid.Length)

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

+20  A: 

38, and the GUID will only use 0-9A-F (hexidecimal!).

{12345678-1234-1234-1234-123456789012}

That's a max of 38 characters in any GUID--they are of constant length. You can read a bit more about the intricacies of GUIDs here.

Note: 38 is the string length including the dashes in between and brackets around them. They are actually 16-byte numbers.

Eric
I think one respresentation surrounds with {}, so that would mean a max of 38
Mitch Wheat
I'm pretty sure you had it right the first time, Eric. guid.ToString() returns a string of length 36, with no braces.
Michael Petrotta
Thanks for you two, what I will need is 36, I said I wanna store Guid.NewGuid.
Shimmy
This is wrong for .NET; you only get 36 characters! You do get the braces (38 characters) for the C# visualizer, but not in code!
Stevo3000
+2  A: 

I believe GUIDs are constrained to 16-byte lengths (or 32 bytes for an ASCII hex equivalent).

Quartz