How to perform Update and Insert in SQL Server 2012 using SQL Bulk insert C# and ignore the duplicate values if already present in database

删除回忆录丶 提交于 2019-12-12 03:31:42

问题


Summary

I have a requirement to modify the content of Database based on some input .txt file that modify thousands of records in database, for each being a business transaction (daily around 50 transaction will performed).

My application will read that .txt file and perform the modification to data in SQL Server database.

The current application that imports the data from DB and perform the data modification in memory (DataTable) and later after that push back to database it does so using SqlBulkCopy into a SQL Server 2008 database table.

Does anyone know of a way to use SqlBulkCopy while preventing duplicate rows, without a primary key? Or any suggestion for a different way to do this?

Already implemented and dropped for performance issues.

Before this I was using SQL statements was generated automated for data modifications but it's really slow, so I thought of loading complete database table into a DataTable (C#) memory perform look up and modifications and accept the changes to that memory ...

One more approach to implement, give me some feedback about my new approach please right me if I am wrong ..

Steps

  1. load to database table into C# DataTable (fill DataTable using SqlDataAdapter)
  2. Once DataTable is in memory, perform data modifications on it
  3. Load again the base table in database and compare in memory prepare the non-existing records and finally perform insert.
  4. push the DataTable to memory using Bulk insert

I cant have Primary key!!!!

Please give me any suggestions for my workflow. and whether i am in right approach to deal my problem?.

来源:https://stackoverflow.com/questions/36389394/how-to-perform-update-and-insert-in-sql-server-2012-using-sql-bulk-insert-c-shar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!