CheckSum function
CHECKSUM_AGG can be used to detect changes in a table.
The order of the rows in the table does not affect the result of CHECKSUM_AGG. Also, CHECKSUM_AGG functions may be used with the DISTINCT keyword and the GROUP BY clause.
If one of the values in the expression list changes, the checksum of the list also generally changes. However, there is a small chance that the checksum will not change.
CHECKSUM_AGG has similar functionality with other aggregate functions.
The following example uses CHECKSUM_AGG to detect changes in the Quantity column of the ProductInventory table.
SELECT CHECKSUM_AGG(CAST(Quantity AS int)) FROM Production.ProductInventory;
Here is the result set.
------------------------
262
UPDATE Production.ProductInventory SET Quantity=125 WHERE Quantity=100;
--Get the checksum of the modified column.
SELECT CHECKSUM_AGG(CAST(Quantity AS int)) FROM Production.ProductInventory;
Here is the result set
------------------------
287
This function become very useful when you wants security in database.
For example if someone unauthorized person tries to change database you can give message that "database has been changed"..