Link to home
Start Free TrialLog in
Avatar of ZuZuPetals
ZuZuPetalsFlag for United States of America

asked on

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

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?
ASKER CERTIFIED SOLUTION
Avatar of carsRST
carsRST
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
Avatar of Reza Rad
just use an execute sql task before the Data flow task, and set sql statement as truncate table ....