Solved

Best practice to remove destination rows before copy new rows from table to table?

Posted on 2010-09-01
3
578 Views
Last Modified: 2013-11-30
I'm trying to get right the trivial use case of copying a table from one database to another.  In the Data Flow view I've got an OLE DB Source -> OLE DB Destination.   I want the destination table to be a mirror of the origin table.

The only problem is that every time I run it the flow appends instead of replacing the previous rows so my destination table size is 1x, 2x, 3x, 4x, etc.

New to SSIS, I don't understand why there isn't an option on the OLE DB Destination properties akin to "[x] Delete current rows before copy?," or even "replace instead of append," but, alas I don't see any feature like that.

What is the best way to remove the destination rows before the transfer?

Best thing I can figure out is to insert an Execute SQL Task to "truncate table MyDestination" ahead of the Data Flow Task that does the transfer.  Is that what everyone else does or did I miss something easy?
0
Comment
Question by:ZuZuPetals
3 Comments
 
LVL 16

Accepted Solution

by:
carsRST earned 500 total points
Comment Utility
>>Best thing I can figure out is to insert an Execute SQL Task to "truncate table MyDestination" ahead of the Data Flow Task that does the transfer.  Is that what everyone else does or did I miss something easy?

You're right on the money.
0
 
LVL 16

Expert Comment

by:vdr1620
Comment Utility
Well, you can definitely take that approach,But if there is any date column in the source and If only data is inserted into OLE DB source is then i would say use a SQL statement with a where clause instead of loading all the data again.. There's also an UPSERT Method which you can use to load the new rows and update any old values..If any values changed in your ole db source
0
 
LVL 30

Expert Comment

by:Reza Rad
Comment Utility
just use an execute sql task before the Data flow task, and set sql statement as truncate table ....
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Need Counts 11 40
ms sql stored procedure 22 75
SQL 2012 and SQL 2014 in memory database 11 28
Help in Understanding a SQL Query 7 24
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
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.

772 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now