如何在SQL Server 2008 R2中捕获表级数据变化?

发布于 2024-11-17 02:08:16 字数 260 浏览 4 评论 0原文

我有大量数据标准化为 100 多个表。有多个应用程序会更改这些表中的基础数据,我想针对这些更改引发事件。我知道的可能的选项是:

  • 更改数据捕获
  • 更改跟踪
  • 在每个表上使用触发器(不好的选择,但可能)

如果有人以前已经这样做过,有人可以分享执行此操作的最佳方法吗?

最后我真正想要的是,如果有一个事务影响了 100 个表中的 12 个,我应该能够冒泡一个事件而不是 12 个。假设有并发用户更改这些表。

I have high volume of data normalized into more than 100 tables. There are multiple applications which change underlying data in those tables and I want to raise events on those changes. Possible options that I know of are:

  • Change Data Capture
  • Change Tracking
  • Using Triggers on each table (bad option but possible)

Can someone share the best way of doing this if someone has already done this before?

What I really want in the end is if there is one transaction that affected 12 tables off 100 I should be able to bubble one event up instead of 12. Assume there are concurrent users change these tables.

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

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

发布评论

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

评论(3

无所谓啦 2024-11-24 02:08:16

我能想到的两个选项:

  1. 触发器是捕获数据库层中更改事件的正确方法
  2. Codewise,我确保在我的应用程序中,每个表仅通过代码中的一个位置进行更改,无论更改是什么(我称之为该表的中心,因为它将许多不同的路径引导到一个地方),在代码层中捕获更改事件变得非常容易

Two options I can think of:

  1. Triggers ARE the right way to capture change events in the DB layer
  2. Codewise, I make sure in my app that each table is changed through only one place in the code, regardless what the change is (I call it a hub for that table, as it channels many different pathways into one place), it becomes very easy to catch change events that way in the code layer
Oo萌小芽oO 2024-11-24 02:08:16

一种可能是 SQL Server 查询通知:使用查询通知

One possibility is SQL Server Query Notifications: Using Query Notifications

长伴 2024-11-24 02:08:16

只要您想“批量”进行多个更改,我认为您应该遵循更改数据捕获更改跟踪的路线(取决于您是否只想知道发生了什么变化或发生了什么变化)。

它们应该由“轮询”过程使用,您每隔几分钟(秒,毫秒???)轮询一次更改并引发事件。这样做的好处是,只要您存储每个表的前一次轮询的最后一个行版本,您就可以随时检查自上次轮询以来的更改。您不依赖于实时触发方法,如果停止,您将永远丢失所有事件。该过程可以在检查每个表的过程中轻松创建,并且您只需要另外 1 个表来存储每个表的最后一个行版本。

此外,这种方法的开销将由您以及轮询发生的频率来控制。

As long as you want to 'batch' multiple changes, I think you should follow the route of Change Data Capture or Change Tracking (depending on whether you just want to know that something changed or what changes happened).

They should be used by a 'polling' procedure, where you poll for changes every few minutes (seconds, miliseconds???) and raise events. The nice thing about this is that as long as you store the last rowversion of the previous poll -for each table- you can check whenever you like for changes since the last poll. You don't rely on a real time triggers approach, that if halted you would loose all events forever. The procedure could be easily created inside a procedure that checks each table and you would need only 1 more table to store last rowversion per table.

Also, the overhead of this approach would be controlled by you and by how frequently the polling happens.

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