在 SQL Server 2000 中使用触发器移动数据的最佳实践

发布于 2024-08-18 10:37:01 字数 480 浏览 0 评论 0原文

我在尝试将数据从 SQL Server 2000 (SP4) 移动到 Oracle10g 时遇到了一些麻烦,因此链接已准备就绪并且可以工作,现在我的问题是如何移动详细数据,我的情况如下:

表 A 是主表 表 B 是详细信息

,两者都与触发器相关(FOR INSERT),

因此我的查询需要查询两者以创建强大的查询,因此当触发器在主表的第一次插入时触发时,它会正常传递,在下一步中用户将插入表 B 中的一个或多个详细信息,因此每当记录增量时触发器都会被触发,我的问题是我需要发送例如:

1 Master - 1 Detail = 2 rows(正常工作) 1 主 - 2 详细信息 = 4 行(麻烦)

在第二种情况下,我解决了在每个插入的每个选择中都会重复数据的细节,我说如果详细信息有 2 个详细信息,则正常情况是它将是 1 行的 2 个选择每个,但在第二个选择中,行数加倍(查询插入的第一个详细信息)

如何使用表 B 上的触发器每次插入移动一行?

I have some troubles trying to move data from SQL Server 2000 (SP4) to Oracle10g, so the link is ready and working, now my issue is how to move detailed data, my case is the following:

Table A is Master
Table B is Detail

Both relationed for work with the trigger (FOR INSERT)

So My query needs to query both for create a robust query, so when trigger get fired on first insert of Master it passed normal, in the next step the user will insert one or more details in Table B, so the trigger will be fired any time the record increment, my problem is that I need to send for example :

1 Master - 1 Detail = 2 rows (Works Normal)
1 Master - 2 Details = 4 rows (Trouble)

In the second case I work around the detail that in each select for each insert it duplicates data, I said if Detail have 2 details the normal is that it will be 2 selects with 1 row each one, but in the second select the rows get doubled (query the first detail inserted)

How can I move one row per insert using triggers on Table B?

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

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

发布评论

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

评论(1

染柒℉ 2024-08-25 10:37:01

大多数情况下,这可以归结为编码错误,我在这里发布了相关博客:

http://www.brentozar.com/archive/2009/01/triggers-need-to-handle-multiple-records/

但是,我担心的是会发生回滚。如果您的 SQL Server 上有一个程序对不同的表连续执行多项操作,并且它们封装在不同的事务中,我可以想象数据将插入 Oracle 但不会插入 SQL Server 的场景。我建议不要使用触发器进行跨服务器数据同步。

相反,请考虑使用 DTS 或 SSIS 之类的工具来定期同步两个服务器。

Most of the time this boils down to a coding error, and I blogged about it here:

http://www.brentozar.com/archive/2009/01/triggers-need-to-handle-multiple-records/

However, I'm concerned about what's going to happen with rollbacks. If you have a program on your SQL Server that does several things in a row to different tables, and they're encapsulated in different transactions, I can envision scenarios where data will get inserted into Oracle but it won't be in SQL Server. I would advise against using triggers for cross-server data synchronization.

Instead, consider using something like DTS or SSIS to synchronize the two servers regularly.

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