• Quick thoughts;

    The HASHBYTES has the 8000 and 4000 character limits for VARCHAR and NVARCHAR data types respectfully. This means that if one wants to create a hash of character strings larger than the limit then one has either to resort to external methods (CLR etc.) or chunk the string accordingly. I have done this in T-SQL by using the following method:

    1) Chop the string into 8000/4000 characters

    2) Hash each chunk

    3) Concatenate the hashes and test for the length

    4) Hash the concatenation, repeating the chopping if longer than the limit.

    5) Finally ending up with one hash.

    This will generate a unique hash for the character string but obviously it will not match other methods which process the whole string in one go.

    The length of the output has nothing to do with the input lenght, it depends on which algorithm is used, available algorithms are MD2, MD4, MD5, SHA, SHA1, SHA2_256 and SHA2_512. There is a performance difference between those and I've found that the SHA1 is normally the fastest and MD5 is close behind.

    For several reasons I'm not to keen on a calculated column for the hashes, performance being an obvious one, I rather hash the content on the insert.

    😎