日期:2014-05-17  浏览次数:20734 次

sqlserver2000中bulk insert 的问题
我在mfc开发中使用sqlserver2000数据库,因为我的数据比较大所以使用bulk insert语句导入txt文件,但是现在我发现我使用该语句后存到数据库中的数据与txt文件中的数据顺序不一致,请问bulk insert有没有保持与txt文档数据顺序相同的方法?只要顺序一致就行。

------解决方案--------------------
bulk insert应该是按照txt中的顺序录入的,
那就看你录入的数据库中的表是以哪个字段为序了,一般哪个字段为聚集索引
就会以哪个字段为默认排序规则
------解决方案--------------------
你说的顺序是指列顺序不一致吗?你的恶FIELDTERMINATOR 是什么?
------解决方案--------------------
可以考虑使用FORMATFILE 参数:
FORMATFILE ='format_file_path'
Specifies the full path of a format file. A format file describes the data file that contains stored responses created by using the bcp utility on the same table or view. The format file should be used if:

The data file contains greater or fewer columns than the table or view.

The columns are in a different order.

The column delimiters vary.

http://msdn.microsoft.com/en-us/library/ms179250.aspx

或者你可以考虑将数据先放到一个TEMP TABLE然后只选取你要插入到目标表的数据列(这个可能更好操作,如果你没用过FORMATE file)