Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing MD5 Hash in SQL Server

Tags:

sql-server

md5

In SQL Server would a varbinary(16) be the most efficient way of storing an MD5 hash? Won't be doing anything with it except returning it in a linq query.

like image 776
Nic Strong Avatar asked Sep 08 '08 03:09

Nic Strong


2 Answers

Null values change things:

A null varbinary(16) is 2 bytes.
A null binary(16) is 16 bytes.
16 bytes stored in varbinary(16) takes 18 bytes.
16 bytes in binary(16) takes 16 bytes.

https://stackoverflow.com/a/3731195

like image 143
Dan Avatar answered Oct 01 '22 03:10

Dan


Based on the documentation on MSDN and my experience, binary is better, since the md5 hash does not vary in size.

The size for a binary data type is n bytes, so the size of the data. The size of a varbinary data type is n bytes + 2 bytes on top of the size of the data.

like image 41
Dale Ragan Avatar answered Oct 01 '22 04:10

Dale Ragan