Tuesday, January 2, 2018

SQL - BINARY_CHECKSUM() to detect row changes

Binary_checksum function is used to compute the checksum value of an entire row of a table or a list of expressions. This function is also used to detect the changes in a table.
Function usage:
  • Binary_checksum(*) is used to compute checksum value for the entire row.
  • Binary_checksum(expression1, 2,….,n) is used to compute checksum value for the given expression list.
Data types that are invalid to compute checksum value are  text, ntext, image, cursor, xml, and noncomparable common language runtime (CLR) user-defined types. So, we should not use these data types in the binary_checksum function.
This function returns an interger value. So, We can use this checksum value for the original row to compare with a current row to check whether there is any change in that particular row for a table.
Binary_checksum() and checksum() functions are have same functionality but the binary_checksum() returns different values for a string value with different case.


e.g.




Reference: checksum() vs. hashbytes()




No comments:

Post a Comment