Ondra Peterka Ondra Peterka - 1 year ago 72
SQL Question

What data type is Guid in SQL server?

In other words, how is guid internally stored and compared by SQL (particularly MS SQL server 2008)? Is it a number or string? Also, is there a big performance hit when using guid as primary key? (Besides the problem with clustering mentioned for exmaple here: GUID as primary key best practices)

I think it should be 128bit number (as descibed for example here: http://blogs.msdn.com/b/oldnewthing/archive/2008/06/27/8659071.aspx), but I can not find the particulars on how it is implemented in SQL server.

Answer Source

16 bytes, exactly as the GUID structure:

typedef struct _GUID {
  DWORD Data1;
  WORD  Data2;
  WORD  Data3;
  BYTE  Data4[8];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download