SQL Server: Text was truncated or one or more characters had no match in the target code page error

来源:互联网 发布:达内软件测试学院 编辑:程序博客网 时间:2024/06/11 01:44

导入CSV到SQL Server真是一件美好的事情,这是转自一个外国人博客里的部分解决方案。但我想吐槽的远不止这个。

1. 如果你的csv比较干净,也就是指一项数据中没有逗号“,”的话,通过下面的方法改改字段长度就好了(微软你们真懒啊,遍历一遍自动设个长度不行啊)

When trying to import a CSV file into a database using the “Import Data” SSIS option in SQL Server Management Studio I kept getting this error:

“Text was truncated or one or more characters had no match in the target code page.”

This was driving me nuts – such a simple thing to do and the tool failed each time. Turns out that, for whatever reason, and despite the data import wizard realising the target table has enough room in the columns, that you have to click on the Advanced tab and say what the size of the destination table columns are going to be (this is before you have selected the destination of course).

sqlserver-dataimport-settings

Once you’ve done this the import should now work perfectly.

You would have thought by now that Microsoft would have made this a bit more intelligent by now…


2. 如果不幸的,你的数据比较复杂,比如某一行数据是这样的

     北京大学, 2012, 40000, "北京,海淀区"

    以我目前的测试情况是,最后的"北京,海淀区"会被切成两个数据,即 ("北京) 和 (海淀区"),引号MS你都不处理让人哭啊。

    折中方案,转换成excel或者其他格式再进行导入,这样sql server就会把数据项区分正确,运气好的话就走通了。

3. 如果还很不幸,和我一样,导成excel之后还是这个问题,还是报告数据超过字段长度,那么,我目前还没解决~我尝试过把对应字段改成text但依然报错,试试再曲线救国转成别的可能不会报错的格式再导入吧。

0 0
原创粉丝点击