How to use Bulk Insert (SQL 2005)

Soldato
Joined
11 Feb 2004
Posts
4,532
Location
Surrey, UK
I have a database containing software details. Its been requested that a new field is created to store an additional piece of information about the software, a field called 'TYPE'.

I have a CSV file containing 'ID' and 'TYPE'.

The 'ID' field is already present in the database and unique for each record.

Is it possible to add the additional information to each record using 'ID' as the lookup value?

I looked on MSDN and came away slightly baffled!
 
I had always presumed BULK INSERT was used to dump content from a csv file into a table with exactly the same number of columns as the csv file has comma delimited text areas. Meaning that you can't do any sort of lookup on the ID or anything and it simply dumps the contents into the table.

Obviously I will be wrong here, and have been using the function completely wrong!
 
BULK INSERT won't be able to directly update your target table, but you may be able to BULK INSERT the CSV file into a different table and then merge the two tables together via an update from the new table into the target table (hope that makes sense).
 
Back
Top Bottom