简体   繁体   English

如何将文本文件的内容插入SQL Server中的表中

[英]How to insert the contents of a text file into a table in SQL Server

I have several files (they are XML but that's not important) that need to be inserted into an existing SQL table (ie I didn't design it.) The table looks like this. 我有几个文件(它们是XML,但这并不重要)需要插入到现有的SQL表中(即我没有设计它。)表格如下所示。

ReportType
  ID (int) <- identity
  Name (varchar(32))
  TransformXSLT (nvarchar(max))

Normally I would do: 通常我会这样做:

INSERT INTO ReportType (Name, TransformXSLT)
VALUES ('template name', '<lots><of><xml><goes><here>...</lots>')

Is there any way to do: 有什么办法吗?

INSERT INTO ReportType (Name, TransformXSLT)
VALUES ('template name', {filename})

I'm using SQL Server Management Studio and Eclipse+Maven to manage the files. 我正在使用SQL Server Management Studio和Eclipse + Maven来管理文件。

BULK INSERT or OPENROWSET(BULK…) are the usual options from T-SQL BULK INSERT或OPENROWSET(BULK ...)是T-SQL的常用选项

After comment... 评论后......

...FROM OPENROWSET(BULK N'C:\Text1.txt', SINGLE_BLOB);

and the "Bulk Exporting or Importing SQLXML Documents" section here 和“批量导出或导入SQLXML文档”部分在这里

Sorry, I've not actually tried this but MSDN says you can 对不起,我实际上没有试过这个,但MSDN说你可以

Have you tried using the SQL Server Import and Export Wizard? 您是否尝试过使用SQL Server导入和导出向导?

Go into SQL Server Management Studio. 进入SQL Server Management Studio。 In Object Explorer, right click the database then Tasks > Import Data.... 在对象资源管理器中,右击数据库,然后单击任务>导入数据....

This will let you import data as a one off exercise, or let you save the resulting SSIS package and re-run it. 这将允许您作为一次性练习导入数据,或者让您保存生成的SSIS包并重新运行它。

Give it a go. 搏一搏。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM