Tutorials

Store Guid as BINARY(16) in MySQL with NHibernate

Why use BINARY type to store a GUID ?

GUID is a 128-bit (16 bytes) integer number. 

In its canonical textual representation, GUID are represented as 32 hexadecimal digits, displayed in five groups separated by hyphens, in the form 8-4-4-4-12 for a total of 36 characters (32 hexadecimal characters and 4 hyphens).

For example: 79d266c1-ca54-4bc9-9b0e-4a988fa1b1dc

It is possible to store it in its human-readable form and in this case we could consider using CHAR(36) but this storage form isn’t suitable for the following reasons :