All the tables have an extra row called checksum which is stored by doing INSERT INTO example_table VALUES ('a','b', BINARY_CHECKSUM('a','b')).

Suppose someone change a row value, obviously the checksum will change, and when I run Select CHECKSUM_AGG(*) FROM example_table, that value will differ from the stored checksum. How can I detect, looping through all tables, what row or table was changed? Can I do this with a Stored Procedure? This is an SQL SERVER database.

  • Audit all tables and detect data changes. That's sort of the point of the question. – user107162 Oct 2 '16 at 17:41
  • 1
    There's a built-in functionality for auditing. – vonPryz Oct 2 '16 at 18:14
select * 
from table 
where BINARY_CHECKSUM('a','b') <> checksumCol 

But if they can change a or b they can change the checksumCol

| improve this answer | |
  • I know it´s not a very good idea to store the checksum, but how can I determine that the new value differs from the actual value? – user107162 Oct 2 '16 at 17:24
  • Use timestamp or just don't give them update authority – paparazzo Oct 2 '16 at 17:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.