批量插入SQL Server [英] Bulk insert in sql server
本文介绍了批量插入SQL Server的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在sql server中使用批量插入工具.我想将数据从文本文件导入到表中
除了我需要动态插入的uniqueidentifier以外.任何解决方案.
i need to use bulk insert facility in sql server.i want to import data from a text file to a table
except the uniqueidentifier that i need to insert dynamically.....any solutions.
推荐答案
对于从文本文件到SQL的批量插入,此链接可能对您非常有用服务器数据库
^ ]
May be this link very useful to you for bulk insert from text file to SQL Server database
http://blog.sqlauthority.com/2008/02/06/sql-server-import-csv-file-into-sql-server-using-bulk-insert-load-comma-delimited-file-into-sql-server/[^]
如果表配置正确,唯一标识符将自动递增-您要做的就是添加行.
至于您的问题,我会这样做(请遵循伪代码):
If your table is configured correctly, the unique identifier will automatically increment - all you have to do is add the rows.
As to your problem, I would do it this way (psuedo-code follows):
open file
create/open connection
create command object
while you have records
{
set the cmd parameters with the data you have to insert for the current record
SqlCommand.ExecuteNonScalar (I would also call a stored proc, but that''s up to you)
}
close connection
这篇关于批量插入SQL Server的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文