有没有一种优雅的方法来跟踪 SQL Server 2008 中一个表的所有列的修改

发布于 2024-09-27 19:14:23 字数 105 浏览 1 评论 0原文

我的数据库中有一个包含 100 列的表。我想创建一个触发器来审核每个更新操作的修改。

我能想到的是为所有列创建更新子句,但它们都是类似的脚本。那么有什么优雅的方法可以做到这一点吗?

There is a table in my database containing 100 columns. I want to create a trigger to audit the modification for every update operation.

What I can think is to create the update clause for all columns but they are all similar scripts. So is there any elegant way to do that?

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

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

发布评论

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

评论(4

与往事干杯 2024-10-04 19:14:23

检查更改数据捕获

更新
CDC 提供对变更的所有详细信息的跟踪。自 SQL Server 2008 起可用。

(更改数据捕获仅在 SQL Server 的企业版、开发人员版和评估版上可用。
来源: http://msdn.microsoft.com/en-us/library/ bb522489.aspx)

更轻量级的解决方案是更改跟踪(同步框架),一个之前提到的code4life,自 SQL Server 2005 起可用。

更新 2:
相关问题(有很多子链接):

Check Change Data Capture

Update
CDC provides tracking of all details of changes. Available since SQL Server 2008.

(Change data capture is available only on the Enterprise, Developer, and Evaluation editions of SQL Server.
Source: http://msdn.microsoft.com/en-us/library/bb522489.aspx)

More lightweight solution is Change Tracking (Sync Framework), the one code4life mentioned before, available since SQL Server 2005.

Update2:
Related questions (with a lot of sublinks):

所谓喜欢 2024-10-04 19:14:23

MSDN 上有这样的资源,您可能会发现它很有帮助:

跟踪服务器数据库中的更改(包括SQL Server 2008)

不过,我不确定您是否使用 SQL Server 2008。

There's this resource on MSDN which you might find helpful:

Tracking Changes in the Server Database (including SQL Server 2008)

I'm not sure if you're using SQL Server 2008 though.

如果没结果 2024-10-04 19:14:23

代码生成?

您是否看过 http://autoaudit.codeplex.com/ 使用的技术?

Code generation?

Have you looked at the techniques which http://autoaudit.codeplex.com/ uses?

陌上青苔 2024-10-04 19:14:23

理论上,您可以使用 1 个触发器并检查 COLUMNS_UPDATED() 来了解哪些列已更改。
(未测试)
此处查看更多信息

Theoretically, you can use 1 trigger and check COLUMNS_UPDATED() to know which columns has changed.
(not be tested)
See more here

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