SQL Server SSIS 事务处理

发布于 2024-12-01 06:47:33 字数 940 浏览 1 评论 0原文

我的组织正在从 2000 年升级到 SQL Server 2008(耶!),而且我不熟悉 Integration Services 的交互工作。

我目前管理着非常大的数据库,每天存储的业务流程交易量达到 500000 到 1000000 笔交易。过去我们对数据库的管理非常糟糕,因此它们已经增长到无法维护的规模。我正在努力提供数据库的日常存档,以便工作数据库更易于管理。我编写了几个存储过程来进行存档,然后修剪工作数据库。然而,在尝试集成服务时,我发现了非常适合我的 SP 目前所做的工作的内置功能。

我创建的是几个执行导出/导入的 SSIS 包。由于我只对某些数据感兴趣,因此我在包中使用了以下形式的自定义查询:

DELETE TransactionTable
OUTPUT
DELETED.*
WHERE (EventTimestamp >= 
DATEADD(D, 0, DATEDIFF(D, 0, (SELECT MIN(EventTimestamp) FROM TransactionTable)))
)
AND (EventTimestamp < 
DATEADD(HH, 0, (DATEADD(YY, -1, DATEDIFF(D, 1, GETDATE()))))
);

该查询获取我感兴趣的数据并将其从工作表中删除。使用 SSIS,此查询生成的输出被放入存档表中。

我的问题是:
由于我想将记录导入到我的存档中,并从同一 SSIS 包内的工作数据库中删除这些记录以确保一致性,因此此查询似乎是执行此操作的方法。然而,我担心交易的结构。我正在从工作数据库中删除记录作为要插入到存档数据库中的输出。
SQL Server 如何处理这种情况下的错误?
运行这个包安全吗?
如果语句生成的输出无效并发生错误,会发生什么情况?
该语句是否会回滚?
只有在所有输出都能够传输到存档时才会提交DELETE吗?
如果没有,我怎样才能达到故障安全状态?

My organization is upgrading to SQL Server 2008 from 2000 (yay!) and I am unfamiliar with the inter workings of Integration Services.

I currently manage very large databases that store business process transactions that amount to between 500000 and 1000000 transactions daily. We've had very poor management of the databases in the past and they have thus grown to an unmaintainable size. I'm working to provide daily archival of the databases so that the working databases are more manageable. I wrote several stored procedures to do an archive and subsequently prune the working databases. However, in dabbling with Integration Services, I've found great built in functionality for the job that my SPs currently do.

What I've created are several SSIS packages that perform an export/import. Since I'm only interested in certain data, I use a custom query in the packages that is of the form:

DELETE TransactionTable
OUTPUT
DELETED.*
WHERE (EventTimestamp >= 
DATEADD(D, 0, DATEDIFF(D, 0, (SELECT MIN(EventTimestamp) FROM TransactionTable)))
)
AND (EventTimestamp < 
DATEADD(HH, 0, (DATEADD(YY, -1, DATEDIFF(D, 1, GETDATE()))))
);

This query grabs the data I'm interested in and deletes it from the working table. Using SSIS, this query produces the output that is placed into the archive table.

My question(s) are:
Since I want to import records into my archive and delete those records from the working database within the same SSIS package to ensure consistency, this query seems to be the way to do it. However, I'm concerned about the structure of the transaction. I'm deleting records from my working database as output to be inserted into my archive database.
How does SQL Server handle errors in this case?
Is running this package safe?
What happens if the output generated by the statement is invalid and an error occurs?
Does the statement get rolled back?
Will the DELETE only be committed if all of the output was able to be transferred to the archive?
If not, how might I be able to achieve a fail-safe condition?

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

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

发布评论

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

评论(1

乖不如嘢 2024-12-08 06:47:33

好消息是,您可以将 SSIS 包设置为在发生任何故障时回滚一组任务。

几乎每个容器/任务(包括包本身)都有一个 TransactionOption 属性。您可以将其设置为必需支持不支持

您可以在此处详细了解每个选项:http://msdn.microsoft.com/en -us/library/ms137690.aspx

显然,可以稍微尝试一下,在不同的步骤上强制出错,看看结果是什么。

The good news is, you can set the SSIS package to rollback a set of tasks if any failure occurs.

There is a TransactionOption property that is available on pretty much every container/task, including the package itself. You can set it to Required, Supported, and NotSupported.

You can details on each option here: http://msdn.microsoft.com/en-us/library/ms137690.aspx

Obviously play around with this a bit, forcing errors on different steps to see what the result is.

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