Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

tsql

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

like image 434
Wachburn Avatar asked Oct 13 '11 11:10

Wachburn


2 Answers

  • 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
like image 99
Mark Byers Avatar answered Nov 16 '22 10:11

Mark Byers


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.

like image 45
HashTagDevDude Avatar answered Nov 16 '22 10:11

HashTagDevDude