SQL Server 2008 - 将整个文本文件批量插入到一个字段中
我有一个文本文件 (txt),其中包含格式化文本(仅换行符、回车符和制表符) 它还包含德语字符。
我想使用 T-SQL 中的批量插入注释将文本文件读入数据库表中的一个字段。
我运行了这个命令:
CREATE TABLE #MyTestTable (
MyData NVARCHAR(MAX)
)
BULK INSERT [#MyTestTable]
FROM 'D:\MyTextFile.txt'
SELECT * FROM #MyTestTable
问题是它将文本文件的每一行读入临时表中的新行。我希望它将整个文件(格式和全部)读入一行。
此外,德语字符似乎已丢失 - 在结果视图中被默认的不可打印字符替换。
有人有什么想法我可以如何实现这一目标吗?
谢谢。
I have a text file (txt) containing formatted text (just line breaks, carriage returns and tabs)
It also contains German language characters.
I want to use the Bulk Insert comment in T-SQL to read in the text file into one field within a database table.
I ran this command:
CREATE TABLE #MyTestTable (
MyData NVARCHAR(MAX)
)
BULK INSERT [#MyTestTable]
FROM 'D:\MyTextFile.txt'
SELECT * FROM #MyTestTable
The problem is that it reads each line of the text file into a new row in the Temp table. I want it to read the whole file (formatting and all) into one row.
Also the German language characters appear to be lost - replaced by a non-printable character default in the Results View.
Anyone any ideas how I can achieve this?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用 ROWTERMINATOR 和 CODEPAGE 参数。默认行终止符是“\r\n”。对于代码页,您需要知道原始文件的编码和数据库的默认排序规则。
另请参阅 http://msdn.microsoft.com/en-us/library/ms188365 .aspx
You can use
ROWTERMINATOR
andCODEPAGE
parameters. Default row terminator is '\r\n'. For the CODEPAGE, you need to know encoding of your raw file and default collation of your DB.Also see http://msdn.microsoft.com/en-us/library/ms188365.aspx
使用:
其中
|
是您的列分隔符。Use this:
Where
|
is your column delimiter.这确实需要一些小的编程工作——一个小时左右的工作,再加上其他测试和尽可能长的运行时间。
This really cries for some minor programming job - an hour work or so, plus naother testing and as long for running as it takes.