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:
- 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)
- import the file to the DB
- delete/archive the file
精彩评论