Skip to content

Instantly share code, notes, and snippets.

@GER-NaN
Created January 9, 2017 14:19
Show Gist options
  • Select an option

  • Save GER-NaN/9f8d9b7dffc8b4ddfadfdeffb25629dc to your computer and use it in GitHub Desktop.

Select an option

Save GER-NaN/9f8d9b7dffc8b4ddfadfdeffb25629dc to your computer and use it in GitHub Desktop.
Using HASHBYTES to calculate decent checksums on table
--Example hashbytes on states table
--https://msdn.microsoft.com/en-us/library/ms174415.aspx
--RoewLength and RowSize were added just for debugging purposes
SELECT
Id = tbl_states.state_id,
Hash = HASHBYTES('MD5', (SELECT tbl_states.* FROM (VALUES(null))X(Y) FOR XML AUTO)),
RowLength = LEN( (SELECT tbl_states.* FROM (VALUES(null))X(Y) FOR XML AUTO)),
RowSize = DATALENGTH( (SELECT tbl_states.* FROM (VALUES(null))X(Y) FOR XML AUTO))
FROM
tbl_states
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment