0

I've just begun using SSIS and I've been trying to set up a data flow where I import data from a CSV file into a table on one of the servers.

I can read from the flat file (CSV) and insert it into SQL server OK, but I need to add an extra step and I can't figure out how: I want to delete all records from the table before I insert the new values.

Does anyone know how to help? Thanks!

  • 1
    That helps! I also found this previous [question](https://stackoverflow.com/questions/20237329/how-to-empty-my-destination-table-before-inserting-new-records-in-ssis) that really helped. – Cristiano Morgado Sep 01 '17 at 16:10
  • No worries at all @GrymByrd. Sometimes it's hard to find the right question while searching, so don't view the closure as a bad thing! – S3S Sep 01 '17 at 16:15

2 Answers2

3

You could use TRUNCATE

Removes all rows from a table or specified partitions of a table

  TRUNCATE TABLE yourdb.yourschema.your_destination_table;

before staring a new importing session

https://learn.microsoft.com/en-us/sql/t-sql/statements/truncate-table-transact-sql

Community
  • 1
  • 1
ScaisEdge
  • 131,976
  • 10
  • 91
  • 107
0

Found the answer in these two previous posts:

How to empty my destination table before inserting new records in SSIS? How to delete large data of table in SQL without log?

Basically, set up a SQL Task that runs the command "TRUNCATE TABLE your.table" and then connect it to your Data Flow task.