CHECKSUM and CHECKSUM_AGG

CHECKSUM:
The checksum value computed over a table row or an expression list is returned by the CHECKSUM function. To create hash indexes, use CHECKSUM. In other words, this function calculates a checksum for a full row or a subset of the row’s columns.

It returns an integer after calculating a hash for one or more values in a single row.

Syntax: CHECKSUM ( * | expression [ ,…n ] )

Example:
SELECT CHECKSUM(EmpNo, Ename, Sal) FROM Emp;

Result:
-353026139
-109265723
-1482178046

CHECKSUM_AGG:
The checksum of a group of values is returned by this function. Null values are ignored by CHECKSUM AGG. CHECKSUM AGG can be followed by the OVER clause. This function, in other terms, generates a checksum for a dataset.

It creates an aggregated checksum for each group using a single integer value from many rows.

Syntax: CHECKSUM_AGG ( [ ALL | DISTINCT ] expression )

“ALL” applies the aggregate function to all values. ALL is the default argument. “DISTINCT” specifies that CHECKSUM_AGG returns the checksum of unique values.

Example:
SELECT CHECKSUM_AGG(Sal) Sal_checksum_agg
FROM Emp;

Result:
6389

Hope you find this article helpful.

Please subscribe for more interesting updates.

2 comments

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s