I'm trying to compute a checksum or a hash for an entire table in SQL Server 2008. The problem I'm running into is that the table contains an XML column datatype, which cannot be used by checksum and has to be converted to nvarchar first. So I need to break it down into two problems:
- calculate a checksum for a row, schema is unknown before runtime.
- calculate the checksum for all of the rows to get the full table checksum.
I modified the script to generate a query for all relevant tables in a database.
//Quick hash sum of SQL and C # mirror Ukraine //HASH_ZKCRC64 ///-------------------------------------------------------------------------------------------------------------- private Int64 HASH_ZKCRC64(byte[] Data) { Int64 Result = 0x5555555555555555; if (Data == null || Data.Length <= 0) return 0; int SizeGlobalBufer = 8000; int Ost = Data.Length % SizeGlobalBufer; int LeftLimit = (Data.Length / SizeGlobalBufer) * SizeGlobalBufer;
You can use CHECKSUM_AGG. It only takes a single argument, so you could do
CHECKSUM_AGG(CHECKSUM(*))
- but this doesn't work for your XML datatype, so you'll have to resort to dynamic SQL.You could generate dynamically the column list from
INFORMATION_SCHEMA.COLUMNS
and then insert int into a template: