?
Solved

4. SSIS- Using one SQL command, how can you insert and update data into a table? Are there any drawbacks using this method?

Posted on 2014-10-15
5
Medium Priority
?
427 Views
Last Modified: 2016-02-11
I'm wondering, when I use a single SQL command in SSIS, how do I do an "insert and update to data in a table"?

Are there any drawbacks using this method?
0
Comment
Question by:MIKE
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 3

Assisted Solution

by:prequel_server
prequel_server earned 668 total points
ID: 40383576
insert is simple and fast,
for updates you'll have to check if the id exists and then you update all columns or changed ones if you like.

if your dataset contains both new and updates you split the rows and process them two sets in separate branches of your data flow.
0
 
LVL 32

Assisted Solution

by:awking00
awking00 earned 664 total points
ID: 40384137
What is the source of your data (e.g. file, another table, etc.)?
0
 
LVL 66

Accepted Solution

by:
Jim Horn earned 668 total points
ID: 40384238
Eyeballeth thy MERGE statement, introduced in SQL 2008, which can perform both an insert and update in a single statement.

I use this all the time for loading data warehouses.

SSIS out of the box does not have a MERGE control, so you'd have to lookup on all key columns, to determine if the row does not currently exist (INSERT), then lookup on all columns to determine if it's an UPDATE or no change. Takes a long time to code and test.  If you have some money to burn buy Pragmatic Works Task Factory which has an UPSERT control which does this in one component.
0
 
LVL 32

Expert Comment

by:awking00
ID: 40384697
The merge statement is the best way to go if the source data is a table, which is why I asked.
0
 
LVL 66

Expert Comment

by:Jim Horn
ID: 40386818
So ... is this question answered?
0

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question