如何将文本文件的内容插入SQL Server中的表 [英] How to insert the contents of a text file into a table in SQL Server
本文介绍了如何将文本文件的内容插入SQL Server中的表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有几个文件(它们是XML,但这并不重要),需要插入到现有的SQL表中(即我没有设计它).该表看起来像这样.
I have several files (they are XML but that's not important) that need to be inserted into an existing SQL table (i.e. I didn't design it.) The table looks like this.
ReportType
ID (int) <- identity
Name (varchar(32))
TransformXSLT (nvarchar(max))
通常我会这样做:
INSERT INTO ReportType (Name, TransformXSLT)
VALUES ('template name', '<lots><of><xml><goes><here>...</lots>')
有什么办法做
INSERT INTO ReportType (Name, TransformXSLT)
VALUES ('template name', {filename})
我正在使用SQL Server Management Studio和Eclipse + Maven来管理文件.
I'm using SQL Server Management Studio and Eclipse+Maven to manage the files.
推荐答案
批量INSERT或OPENROWSET(BULK…)是T-SQL的常用选项
BULK INSERT or OPENROWSET(BULK…) are the usual options from T-SQL
评论后...
...FROM OPENROWSET(BULK N'C:\Text1.txt', SINGLE_BLOB);
和批量导出或导入SQLXML文档"部分此处
and the "Bulk Exporting or Importing SQLXML Documents" section here
对不起,我实际上没有尝试过,但是MSDN说可以.
Sorry, I've not actually tried this but MSDN says you can
这篇关于如何将文本文件的内容插入SQL Server中的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文