开发者

import only new or updated records into sql database, using bcp to import and export

开发者 https://www.devze.com 2023-02-28 07:25 出处:网络
I am having a csv file. Now, i have to import all the data from this file into my sql database, mdf file.

I am having a csv file. Now, i have to import all the data from this file into my sql database, mdf file.

ItemID

178

212

3423

I would do the import simply from the bcp. But, after some time the fil开发者_高级运维e is updated with some new records and i want that this time i would only take the new records and insert into the sql database. How to do this? Will i have to match the existing ItemIDs, or use a Primary Key on the ItemID column, and when it would automatically reject the duplicate records, or shall i add a new column as DateTimeofInsert, and then go accordingly, Please sugget?:

ItemID

178

212

3423

4676

782

2308

Also , am using Sql Server Express, so is there any option to automate this process by using Scheduling Jobs etc?


You could just keep track of what line number you process up to each time. So each time your process picks up the file to load new rows into the db, you start from the next line in the file that you last got to. Saves any matching up.

Or, each time you process the file, you could follow this approach:

  1. rename the file (so it won't be written to any more, and the process that is writing to the file will create a new file)
  2. import the file to the DB
  3. delete/archive the file
0

精彩评论

暂无评论...
验证码 换一张
取 消