CHECKSUM#
Returns a checksum computed over one or more expressions. The function is variadic (one or more arguments), order-sensitive (changing the argument order changes the result) and deterministic (the same arguments in the same order always return the same value).
Syntax#
CHECKSUM ( expression [ , expressionN ] )
SQL Server also supports the row form CHECKSUM ( * ), which checksums every column of the
current row. That form is not supported by Querona.
Arguments#
expression
One or more expressions, evaluated and folded in the order given.
Return types#
int
Remarks#
CHECKSUM folds character arguments case-insensitively under the default collation, so
CHECKSUM('a') and CHECKSUM('A') return the same value — unlike BINARY_CHECKSUM,
which is case-sensitive. Trailing spaces are ignored, matching char/varchar comparison
semantics, and an empty string contributes nothing to the result.
Querona hashes CHECKSUM in its own engine, byte-exact with SQL Server, for a specific
argument subset: the integer family (bit, tinyint, smallint, int, bigint),
ASCII char/varchar under the default collation, and binary/varbinary. Every other
data type SQL Server’s CHECKSUM accepts — nvarchar/nchar, the date/time family,
decimal/numeric/money/smallmoney, float/real, uniqueidentifier and
sql_variant — cannot be hashed byte-exactly in the engine, so a query that uses one is
evaluated on a SQL Server data source, which computes it byte-exactly. This routing is
automatic and the returned value is unchanged; such a call fails only when no data source able to
evaluate it is available. text, ntext, image and xml arguments are invalid, as in
SQL Server (Msg 8116).
Note
Engine-local char/varchar hashing is byte-exact only for ASCII characters under the
default collation. A value containing bytes above 127 raises the engine error, and a column
under a non-default collation may differ from SQL Server; evaluate such values on a SQL Server
data source for an exact result.
Note
The row form CHECKSUM ( * ) is not supported.
Examples#
SELECT CHECKSUM('a'); -- 142
SELECT CHECKSUM('A'); -- 142 (case-insensitive, same as 'a')
SELECT CHECKSUM('a '); -- 142 (trailing space ignored)
SELECT CHECKSUM(''); -- 0 (empty string contributes nothing)
-- Msg 8116: Argument data type xml is invalid for argument 1 of CHECKSUM function.
SELECT CHECKSUM(CAST('<a/>' AS xml));