SQL Server provides a function HashBytes function that returns the SHA1 , MD2 , MD4 and few other hash value of the specified input.
How to return the SHA1 hash value of a string in SQL Server ?
Just pass the ‘SHA1’ as the first parameter and the input as second parameter value to the HashBytes function to get the SHA1 hash value.
DECLARE @input nvarchar(max); SELECT @input = CONVERT(nvarchar,'Welcome to Abundantcode.com'); SELECT HashBytes('SHA1', @input); GO
Hi. I did that. but it works only on limited length of a string.
If I will compare two long strings. and change the tail or in the middle of one of them, it will generate the same HASH.
and that’s annoying!
what is the best way (except the obvious limitation of HASH algorithm) , to generate a HASH for a whole table in SQL?