What is the fastest way of updating a number of rows in table (cca 1 million), using the technologies in the tags?
The statement looks something like this:
UPDATE MyTable SET MyColumn = 2 WHERE MyTable.ID = 1
UPDATE MyTable SET MyColumn = 3 WHERE MyTable.ID = 3
UPDATE MyTable SET MyColumn = 5 WHERE MyTable.ID = 7
UPDATE MyTable SET MyColumn = 1 WHERE MyTable.ID = 45
UPDATE MyTable SET MyColumn = 0 WHERE MyTable.ID = 234
And so on.. Additional description:
- No pattern to the numbers.
- Source is a file, it updates changes to existing records, from a file.
- File contains modifications to existing records. I hvae to reflect those changes to the database. Notice how I already know the ID. That is not a problem.
Another possible description. Given a list of IDs, paired up with a value, what is the fastest way to update the records with the ID primary key (MyTable.ID), with the paired value (MyColumn)? Just to be more clear. I am given a (source) file, with some values written to the file. The source file, from which i extract data for importing(updating) to a database, looks like this:
2, 1
3, 3
5, 7
1, 45
0, 234
I will accept an answer using pure TSQL, or something from an ORM or any different provider.