C# - 插入使用存储过程的多个行 [英] C# - Inserting multiple rows using a stored procedure
问题描述
我有对象的列表,这个列表中包含大约400万的对象。有一个存储过程是需要的对象的属性作为参数,可以使一些查询,并把它们插入到表中。
I have a list of objects, this list contains about 4 million objects. there is a stored proc that takes objects attributes as params , make some lookups and insert them into tables.
什么;插入这间4亿个对象,以dB为单位的最有效的方法是什么?
what s the most efficient way to insert this 4 million objects to db?
我如何做的:
-- connect to sql - SQLConnection ...
foreach(var item in listofobjects)
{
SQLCommand sc = ...
// assign params
sc.ExecuteQuery();
}
这一直很慢。
有没有更好的方式来做到这一点?
is there a better way to do this?
这个过程将是一个计划任务。我将运行这个不断小时,所以我期望高容量的数据是这样的。
this process will be a scheduled task. i will run this ever hour, so i do expect high volume data like this.
推荐答案
看看的的 SqlBulkCopy类
根据您的评论,转储数据到一个临时表中然后执行查找并插入到基于从一个进程真正的表集....这将是比排排快得多
based on your comment, dump the data into a staging table then do the lookup and insert into the real table set based from a proc....it will be much faster than row by row
这篇关于C# - 插入使用存储过程的多个行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!