开发者

SQL Update Trigger not always an update

So I've got a simple update trigger that copies the the deleted data into another table of the same format, with the addition of the modified date. It works great, however there are a lot of cases in the application code when an update is performed that doesn't actually change any values.

I开发者_StackOverflow社区'm trying to avoid these being picked up in the audit tables.

Does anybody have any suggestions on how I can fix this, without changing my application code. Possibly a simple comparison of the rows to check for changes?

Thanks


Unfortunately, it is a column by column comparison in the trigger

Edit: for not guaranteed 100% accuracy, you can use CHECKSUM(*). HashBytes is better


The author of this article details an interesting solution that will work in some cases. He selects from the current and deleted tables FOR XML, runs those through HashBytes() and does a comparison of the results.

The article includes well-written source. I was able to modify it quickly for use in my schema. I dropped the HashBytes() conversion and just compared the XML values in order to get around potential issues with HashBytes(). I've tested the solution lightly, and it seems to work as expected.

There's a link in the comments section of the article to another interesting article on the subject, as well.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜