SQL Server : Taking Numerical Characters and Hashing them under with a max length of 20 characters?

For hashing in general, I'd use the HASHBYTES function. You can then convert the binary data to a string and just pick the first 20 characters, that should still be unique enough.

Up vote 0 down vote favorite share g+ share fb share tw.

Hello I was trying to find a good way to hash a set of numerical numbers which its output would be under 20 characters that are positive and unique. Any one have any suggestions? Sql sql-server sql-server-2008 hashing link|improve this question asked Nov 15 '11 at 16:01user10479491.

– Alex K. Nov 15 '11 at 16:08 I'm not aware that you can hash to a specific data size and guarnatee uniqueness. Do you have examples of what you are trying to here, and why?

We may be able to offer alternative approaches, and/or close-enough approaches. For example, if you're hashing to speed up a search, indexes already do that. If you want to hash two identical values to generate a unique identifier for each, IDENTITY columns will do something like that... – Dems Nov 15 '11 at 16:10 @Dems The asker most likely means "unique enough": stackoverflow.com/questions/2444321/… – Michael J Swart Nov 15 '11 at 16:16 @Dems, no hash can guarantee uniqueness.

But crypto hash algorithms such as SHA1 do a good job of reducing the collision probability to an accepably low level. If you then take just a part of that hash (just like Git or Mercurial do for the "friendly" changeset IDs) the collision probability is still very low, at an acceptable level for most applications. – Lucero Nov 15 '11 at 16:17 @Lucero - What about hashing to an output space that is dimensionally larger than the input space?

If you have n inputs, with n^2 technically possible output hash values, is it possible to codify the hashing function to guarantee no collisions? – Dems Nov 15 '11 at 16:32.

For hashing in general, I'd use the HASHBYTES function. You can then convert the binary data to a string and just pick the first 20 characters, that should still be unique enough. To get around HASHBYTES limitations (8000 bytes for instance), you can incrementally hash, e.g. For each value concat the previous hash with the value to be added and hash that again.

This will make it unique with order etc. and unless you append close to 8000 bytes in one value it will not cause data truncation for the hashing.

The string to be hashed is at max 8-9 characters. Thank you all for your answers – user1047949 Nov 15 '11 at 22:41.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions