What is the difference between CHECKSUM_AGG() and CHECKSUM()?

11,937

Solution 1

  • CHECKSUM calculates a hash for one or more values in a single row and returns an integer.
  • CHECKSUM_AGG is an aggregate function that takes a single integer value from multiple rows and calculates an aggregated checksum for each group.

They can be used together to checksum multiple columns in a group:

SELECT category, CHECKSUM_AGG(CHECKSUM(*)) AS checksum_for_category
FROM yourtable
GROUP BY category

Solution 2

CHECKSUM_AGG will perform a checksum across all the values that are being aggregated, coming up with a value. It's typically used to see if a collection of values (in the group) has generally changed.

CHECKSUM is intended to build a hash index based on an expression or column list. One example of using a CHECKSUM is to store the unique value for the entire row in a column for later comparison.

Share:
11,937
Wachburn
Author by

Wachburn

Updated on June 09, 2022

Comments

  • Wachburn
    Wachburn about 2 years

    What is the difference between CHECKSUM_AGG() and CHECKSUM() ?