Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. SQL Server
  3. Question
SQL Server

What is The Best Data Type to Store the Result of HASHBYTES('MD5', ...)?

Asked by Andrew Jenkins Apr 22, 2021 2.1K views 1 answer
Share

About this question

Please suggest the best data type to store the results of the HASHBYTES('MD5', ...)? It outputs 16 bytes of binary as follows: e.g.

I could store it in the three data types: char(34) binary(16) (I think - I read here (https://stackoverflow.com/questions/14722305/what-kind-of-datatype-should-one-use-to-store-hashes#16680423) that using the same algo should return the same number of bytes every time regardless of the input string) other?

Every row will have a value (no nulls), and the column will be used for comparison against a similar column in another table. Which is the best data type to store  SQL server HASHBYTES output for use as described above? I was thinking that since fixed-length data types can sometimes be more efficient on joins, etc. binary(16) vs varbinary(8000) (the default output of HASHBYTES) seems best, and binary(16) vs a varchar(34) is better since it would use less storage space.

Your answer

1 Answer

More SQL Server discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest SQL Server Blogs

Guides, tips and career advice on SQL Server from JanBask experts.