
Use this hash value to build hash indexes. Return typesĬHECKSUM computes a hash value, called the checksum, over its argument list. Noncomparable data types include:Īnother noncomparable data type is sql_variant with any one of the preceding data types as its base type.Īn expression of any type, except a noncomparable data type. CHECKSUM returns an error if any column has a noncomparable data type. This argument specifies that the checksum computation covers all table columns. They don’t have to, but may vary, based on the SQL Server configuration.This syntax is not supported by serverless SQL pool in Azure Synapse Analytics.

Furthermore, HASHBYTES is system independent, comprehensible and suitable for cross database/platform software. E.g.: to determin whether a row has been changed. HASHBYTES focuses on a single value, while CHECKSUM and BINARY_CHECKSUM are capable of hashing an entire row which may be handy in some cases. The benchmark hashes a 500KB file.įrom my point of view, the three hashing algorithm do serve a different purpose. But at the end of the day the overall result should reflect a rough insight. The benchmark will surely vary among different system specifications. Furthermore, HASHBYTES offers more than one implementation: MD2, MD4, MD5, SHA, SHA1, SHA2_256, SHA2_512. In other words if you plan to target not only TSQL, consider using HASHBYTES right away. Sadly, it only works for Strings but not for binaries. There is an reverse engineered version for CHECKSUM. Hence, if you require to calculate the hashes within your application, you are out of luck. Because those two functions are only available on the SQL Server, one won’t be able to pre-calculate hash values outside of the domain.

CompatibilityĬHECKSUM and BINARY_CHECKSUM is a Transact-SQL proprietary implementation and its source code is not available for the public. (Best case) HASHBYTES does offer the best unique representation and narrows down the possibility of intersections. Even if we manage to hash 4.294.967.296 unique data entries, we will run consequently into hash collision upon the next insert. (We consider using SHA2_512 with HASHBYTES)Įven thought CHECKSUM and BINARY_CHECKSUM do have no input bit-length limitation (more or less, See Limitations) they only do return 4 bytes, in order to represent a hash value. In order to analyse the uniqueness, lets have a closer look on the function’s return values.

With that said, based on the chosen hash function, an additional limitation may apply: The bit-length of an argument. On the other hand, HASHBYTES only accepts one input column. As the taxonomy already reflects, CHECKSUM and BINARY_CHECKSUM do accept more than one column as an input. We need to differ between the argument count limitation, and the bit length limitation. The Taxonomy lacks “Limitation”, simply because this topic derives a certain complexity.
