SQL更新触发器并不总是更新

发布于 2024-10-04 04:26:53 字数 202 浏览 2 评论 0原文

因此,我有一个简单的更新触发器,它将删除的数据复制到相同格式的另一个表中,并添加修改日期。它工作得很好,但是在应用程序代码中有很多情况下,执行更新时实际上不会更改任何值。

我试图避免这些被纳入审计表中。

有没有人对我如何解决这个问题有任何建议,更改我的应用程序代码。可能是对行进行简单比较以检查更改?

谢谢

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'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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夏天碎花小短裙 2024-10-11 04:26:53

不幸的是,它是触发器中的逐列比较

编辑:为了不保证100%的准确性,您可以使用校验和(*)HashBytes 更好

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

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

浪漫之都 2024-10-11 04:26:53

文章详细介绍了一个在某些情况下有效的有趣解决方案。他从当前和已删除的表中选择 FOR XML,通过 HashBytes() 运行这些表并对结果进行比较。

这篇文章包括写得好的来源。我能够快速修改它以在我的架构中使用。我放弃了 HashBytes() 转换,只比较 XML 值,以避免 HashBytes() 的潜在问题。我已经稍微测试了该解决方案,它似乎按预期工作。

文章的评论部分也有一个链接,指向另一篇关于该主题的有趣文章。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文