使用SSIS将3年以上的记录从一个数据库(生产DB)移动到另一个数据库(归档DB) [英] Move Records Which are older than 3 years from One Database (Production DB) to Another DB (Archive DB) Using SSIS

查看:127
本文介绍了使用SSIS将3年以上的记录从一个数据库(生产DB)移动到另一个数据库(归档DB)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要求将早于三年的数据从生产数据库移至存档数据库,一旦移动,则从生产数据库中删除这些记录,因此在任何时间点,生产数据库仅具有最近三年的记录.

Requirement is to Move Data Older than 3 years from Production DB to Archive DB , and Once Moved Delete those records from Production DB , so at any point of time Production DB will have only last three years of records.

我想通过SSIS实现这一目标,我阅读了很多有关数据归档的文章,但找不到最佳的解决方案.

i want to achieve this by SSIS , i read quite a few articles about Data Archival but couldn't figure out the best Approch.

我是SSIS的新手

我想完全实现这样的目的(在下面的链接中给出答案),并带有额外的条件,即仅移动3年以上的记录,然后删除这些记录.

i want to achieve exactly something like this (answer given in Below link)with extra condition saying move only those records which are older than 3 years and then delete those records.

https://dba.stackexchange.com/questions/25867/将数据从一个数据库移动到另一个使用的siss

可接受的答案标准应该解决

Criteria for an accepted answer answer should address

  • 可扩展性
  • 复杂性
  • 故障处理
  • 可靠性

推荐答案

您可以使用OUTPUT子句删除并一次性返回要移动的数据.

You can use the OUTPUT clause to delete and return the data to be moved in one go.

create table ProductionTable
(
    ValueDate   datetime        not null
    , Data      varchar(max)    not null
)

insert ProductionTable values ('20100101', '3 years ago')
insert ProductionTable values ('20130425', 'this year')
insert ProductionTable values ('20130426', 'this year')

delete ProductionTable
output deleted.ValueDate, deleted.Data
where ValueDate <= dateadd(year, -3, getdate())

还可以在 SQLFiddle

现在,我将向您展示在SSIS中重现示例所需的确切步骤:

Now I will show you the exact steps you need to follow in SSIS to reproduce the example:

  1. 创建一个新项目并为ProductionDB和ArchiveDB定义数据源.
  2. 在控制流"选项卡中,创建数据流任务".
  3. 在数据流"选项卡中,创建"OLE DB源"和"OLE DB目标".
  4. 在"OLE DB源"中,选择ProductionDB,然后选择"SQL命令"作为数据访问模式.粘贴带有输出子句的delete语句.
  5. 单击列",然后单击确定.
  6. 在"OLE DB目标"中,选择ArchiveDB,然后选择表或视图-快速加载"作为数据访问模式,然后选择您的ArchiveTable.
  7. 单击映射",然后单击确定".
  8. 运行该程序包,您应该能够验证是否已从ProductionTable中删除一行并将其移至ArchiveTable.

希望有帮助.

其他要记住的事情,因为您要删除和移动数据,所以事务的一致性非常重要.想象一下,在删除/移动过程中,服务器宕机了,然后您最终删除了数据,但没有将其保存到存档中.

Other things to keep in mind, because you are deleting and moving data around, transactional consistency is very important. Imagine half way through your delete/move, the server went down, you then end up with data being deleted but not made it to the archive.

如果不确定如何通过执行事务一致性来保护数据,请寻求其他SQL/SSIS专家的帮助,以了解如何在SSIS中使用事务.

If you are unsure about how to protect your data by enforcing transactional consistency, please seek help from other SQL/SSIS experts on how to use transactions in SSIS.

这篇关于使用SSIS将3年以上的记录从一个数据库(生产DB)移动到另一个数据库(归档DB)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆