0

I am having a list of records which I need to insert or update in a SQL DB based on whether the record is present or not present in the database.

The current flow is I process each record 1 by 1 and then call a Stored Procedure from my C# code which does the task of inserting or updating the database.

The above process is very inefficient, Can i use SQL Bulk Copy to insert these in once into the SQLDb .

Will above increase the performance .

Regards Ankur

Ankur Garg
  • 2,553
  • 8
  • 30
  • 41

1 Answers1

2

SqlBulkCopy can only insert. If you need to upsert, you might want to SqlBulkCopy into a staging table (a separate table off to one side that isn't part of the main model), and then do the merge in TSQL. You might also want to think about concurrency (how many people can be using the staging table at once, etc).

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900