批量更新的SQL Server C# [英] Bulk update SQL Server C#
问题描述
我有一个270K行数据库的主键中期
和一个名为值
列,我有一个文本文件,中期的和值。现在我想,这样每个值被分配到正确的中间来更新该表。
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.
我目前的做法是阅读从C#中的文本文件,并更新表中的行为,我读每一行。必须有更快的方式做的事情,我觉得..任何想法?
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?
编辑:有表中的其他列,所以我真的需要一个方法的更新的根据中期
There are other columns in the table, so I really need a method to update according to mid.
推荐答案
您可以使用SQL Server导入和导出向导:
You could use the SQL Server Import and Export Wizard:
http://msdn.microsoft.com/en-us/library/ ms141209.aspx
另外,您可以使用 BULK
TSQL语句:
Alternatively you could use the BULK
TSQL Statement:
BULK
INSERT YourTable
FROM 'c:\YourTextFile.txt'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
)
GO
SELECT * FROM YourTable
GO
假设你在拆分逗号分隔符。如果你使用的是其他字符,例如一个空格,该FIELDTERMINATOR更改为相关的字符。
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
这篇关于批量更新的SQL Server C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!