Bulk update SQL Server C#
.net, c#, sql, sql-server, t-sql
Solution
You could use the SQL Server Import and Export Wizard:
http://msdn.microsoft.com/en-us/library/ms141209.aspx
Alternatively you could use the `BULK` TSQL Statement:
BULK
INSERT YourTable
FROM 'c:\YourTextFile.txt'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
)
GO
SELECT * FROM YourTable
GO
Assuming you are splitting on a comma delimiter. If you are using another character such as a space, change the FIELDTERMINATOR to the associated character.
Edit (To achieve the update from my comment):
UPDATE RealTable
SET value = tt.value
FROM
RealTable r
INNER JOIN temp_table tt ON r.mid = tt.mid
Problem
I have a 270k-row database with primary key `mid` and a column called `value`, and I have a text file with mid's and values. Now I would like to update the table such that each value is assigned to the correct mid. My current approach is reading the text file from C#, and updating a row in the table for each line that I read. There must be quicker way to do things I feel.. any ideas? EDIT: There are other columns in the table, so I really need a method to update according to mid.