[英]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:
我可以通过以下方式做到这一点:
( 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: 到目前为止,我尝试了:
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.