简体   繁体   English

SQL Server SSIS事务处理

[英]SQL Server SSIS Transaction Handling

My organization is upgrading to SQL Server 2008 from 2000 (yay!) and I am unfamiliar with the inter workings of Integration Services. 我的组织正在从2000升级到SQL Server 2008(是!),但我不熟悉Integration Services的交互作用。

I currently manage very large databases that store business process transactions that amount to between 500000 and 1000000 transactions daily. 我目前管理非常大的数据库,这些数据库每天存储的业务流程交易量为500000至1000000。 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. 但是,在浅析浅析Integration Services时,我发现了出色的内置功能可用于我的SP当前完成的工作。

What I've created are several SSIS packages that perform an export/import. 我创建的是几个执行导出/导入的SSIS包。 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. 使用SSIS,此查询将产生输出,该输出将放置在存档表中。

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. 由于我想将记录导入到存档中,并从同一SSIS包中的工作数据库中删除这些记录以确保一致性,因此此查询似乎是实现此目的的方法。 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? 在这种情况下,SQL Server如何处理错误?
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? 仅当所有输出都可以传输到归档时,才提交DELETE吗?
If not, how might I be able to achieve a fail-safe condition? 如果没有,我如何能够达到故障安全条件?

The good news is, you can set the SSIS package to rollback a set of tasks if any failure occurs. 好消息是,如果发生任何故障,您可以将SSIS包设置为回滚一组任务。

There is a TransactionOption property that is available on pretty much every container/task, including the package itself. 在几乎每个容器/任务(包括包本身)上都有一个TransactionOption属性。 You can set it to Required , Supported , and NotSupported . 您可以将其设置为RequiredSupportedNotSupported

You can details on each option here: http://msdn.microsoft.com/en-us/library/ms137690.aspx 您可以在此处详细了解每个选项: http : //msdn.microsoft.com/zh-cn/library/ms137690.aspx

Obviously play around with this a bit, forcing errors on different steps to see what the result is. 显然,您需要进行一些操作,在不同的步骤上强制执行错误,以查看结果是什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM