Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to empty my destination table before inserting new records in SSIS?

I use SSIS to generate and transform new data for later use in a new system. I have a problem every time I run my SSIS Package, it keeps inserting new records to my destination tables.

How can I empty my destination table (/OLE DB Destination) first and then inserting the newly generated records?

Currently the workaround for this problem is performing a delete from DestTable before running my package.

like image 902
Tassisto Avatar asked Nov 27 '13 08:11

Tassisto


People also ask

How do I truncate a target table in SSIS?

Step 1: Define connections to Source and Target. Step 2: Get the table name and save it in a user variable. Step 3: Truncate the table in Step 2. Step 4: Load the Target table ?

How do I delete a table in SSIS?

Use Execute SQL Task to configure the connection and the SQLStatement. Using the create table code. If you want to drop table just use the code 'drop tablename' in the same way.


2 Answers

Put your delete statement in an Execute SQL Task. Then make it the first component of your flow. The component looks something like this:

enter image description here

like image 116
TsSkTo Avatar answered Oct 16 '22 11:10

TsSkTo


Create an Execute SQL task. Have it run first. For the sqlstatment do.

Truncate table DestTable

Using truncate table is better then using delete as it ignores all the indexes and just removes everything.

For a little background info. I will try and explain why you should use truncate table instead of delete table. Delete table is a row based operation this means that each row is deleted. Truncate table is a data page operation the entire data page is delocated. If you have a table with a million rows it will be much faster to truncate the table then it would be to use a delete table statment.

like image 33
DaImTo Avatar answered Oct 16 '22 13:10

DaImTo