简体   繁体   English

SSIS(在SQL Server 2012中):查找组件中的Upsert

[英]SSIS (in SQL Server 2012): Upsert in Lookup component

I have > 10 packages that need to update/insert in the dataflow. 我有> 10个需要更新/插入数据流的软件包。 I am able to do it by: 我可以通过以下方式做到这一点:

  • Lookup => Match output branch => OLE DB Command. 查找=>匹配输出分支=> OLE DB命令。
  • Lookup => No Match output branch => OLE DB Destination. 查找=>没有匹配输出分支=> OLE DB目标。

( http://www.rad.pasfu.com/index.php?/archives/46-SSIS-Upsert-With-Lookup-Transform.html ) ( http://jahaines.blogspot.com/2009/09/sss-performing-upsert.html ) http://www.rad.pasfu.com/index.php?/archives/46-SSIS-Upsert-With-Lookup-Transform.html )( http://jahaines.blogspot.com/2009/09/sss -performing-upsert.html

However, I was wondering if there is some way I can use the "Merge" statement in Lookup (or in any other) component such that I can do something like: 但是,我想知道是否可以通过某种方式在Lookup(或任何其他)组件中使用“ Merge”语句,以便可以执行以下操作:

MERGE [DBPrac].[dbo].[TargetTable] AS tt
USING [SourceTable] AS st ON tt.Id = st.Id

WHEN MATCHED THEN --* Update the records, if record found based on Id.
   UPDATE 
      SET tt.SSN = st.SSN 
          ,tt.FirstName = st.FirstName
          ,tt.MiddleName = st.MiddleName
          ,tt.LastName = st.LastName
          ,tt.Gender = st.Gender
          ,tt.DateOfBirth = st.DateOfBirth
          ,tt.Email = st.Email
          ,tt.Phone = st.Phone
          ,tt.Comment = st.Comment

WHEN NOT MATCHED BY TARGET THEN --* Insert from source to target.
    INSERT (Id, SSN, FirstName, MiddleName, LastName, Gender, DateOfBirth, Email, Phone, Comment)
    VALUES (st.Id, st.SSN, st.FirstName, st.MiddleName, st.LastName, st.Gender, st.DateOfBirth, st.Email, st.Phone, st.Comment)
;

SELECT @@ROWCOUNT;

SET IDENTITY_INSERT [dbo].[TargetTable] OFF
GO

So far I tried: 到目前为止,我尝试了:

  • In Lookup component's "Advanced" pane in "Custom query", I tried to use the above query, but stumbled upon the "SourceTable". 在“自定义查询”中查找组件的“高级”窗格中,我尝试使用上述查询,但偶然发现了“ SourceTable”。 Don't know how to get hold of input recordset in the "Custom query" (Don't know if it is even possible). 不知道如何在“自定义查询”中保存输入记录集(甚至不知道是否可能)。

Any help and/or pointer would be great. 任何帮助和/或指针将是巨大的。

If I understand your question correctly, just execute the Merge statement using an Execute SQL task. 如果我正确理解了您的问题,只需使用Execute SQL任务执行Merge语句。 Then you dont need any Lookups. 然后,您不需要任何查找。 We use the same strategy for our warehouse's final load from staging. 对于仓库的最终分期装载,我们使用相同的策略。

Yes you can use MERGE but you need to load your data into a staging table. 是的,您可以使用MERGE,但需要将数据加载到临时表中。 This is the 'ELT' method - extract, load (into database), transform, as opposed to the 'ETL' method - extract, transform (in package), load (into database) 这是“ ELT”方法-提取,加载(进入数据库),转换,而不是“ ETL”方法-提取,转换(在程序包中),加载(进入数据库)

I usually find the ELT method faster and more maintainable, if you don't mind working with SQL scripts. 如果您不介意使用SQL脚本,我通常会发现ELT方法更快,更可维护。 Certainly a single bulk update is faster than the row by row update that occurs in SSIS 当然,单个批量更新比SSIS中发生的逐行更新要快

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

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