I've some tables that shouln't be modified after some final steps in a process.
To validate that it wasn't made any modifications (after the final state) I'm thinking about making an hash of all the columns. So, for each row I:
In the future, to validate, I simply do the hash again and compare with the result obtained previously.
Is there a better way to do it?
If not, when converting the other data types to varchar, should I use convert(varchar, ...)
or depending on the type of the data should I define a length to the varchar
?
Personally if I were taking that approach I'd use a timestamp field instead of a hash. That will automatically update any time anything happens to the row and is a whole easier than what your describing.
The verification approach would be similar to what you describe in your question. To make auditing easy you could use a trigger to store the timestamp value off to another table.
Or... speaking of triggers. If your true intent is to block updates entirely you could use a trigger to cancel the update entirely (unless it meets specific requirements that you set).
This is all assuming you have a reason for not just locking down the rights on the table by revoking update / delete rights to all users. (which would be the easiest of all).