【发布时间】:2013-10-27 03:29:01
【问题描述】:
在我们的项目中,我们使用 bcp 命令导出大约数百万行并将输出记录到输出文件中。
对于 bcp 导入,我可以使用指定编号的 -b 开关来控制 bcp 命令的输出。要批量导入的行数。输出是这样的:
Starting copy...
1000 rows sent to SQL Server. Total sent: 1000
1000 rows sent to SQL Server. Total sent: 2000
1000 rows sent to SQL Server. Total sent: 3000
1000 rows sent to SQL Server. Total sent: 4000
1000 rows sent to SQL Server. Total sent: 5000
1000 rows sent to SQL Server. Total sent: 6000
1000 rows sent to SQL Server. Total sent: 7000
1000 rows sent to SQL Server. Total sent: 8000
1000 rows sent to SQL Server. Total sent: 9000
1000 rows sent to SQL Server. Total sent: 10000
1000 rows sent to SQL Server. Total sent: 11000
1000 rows sent to SQL Server. Total sent: 12000
SQLState = 22001, NativeError = 0
可以通过增加-b 开关发送的数量来轻松减少:
Starting copy...
10000 rows sent to SQL Server. Total sent: 10000
SQLState = 22001, NativeError = 0
12406 rows copied.
Network packet size (bytes): 4096
Clock Time (ms.) Total : 75 Average : (165413.3 rows per sec.)
但是对于 bcp 导出,我无法控制输出,对于一百万行,日志变得太大,例如。下面的命令
bcp Temp.dbo.TestTable out outdata.txt -t , -f file.fmt -S Server -U user-P password -m 10
输出这个:
Starting copy...
1000 rows successfully bulk-copied to host-file. Total received: 1000
SQLState = S1000, NativeError = 0
Error = [Microsoft][ODBC Driver 11 for SQL Server]Warning: BCP import with a format file will convert empty strings in delimited columns to NULL.
1000 rows successfully bulk-copied to host-file. Total received: 2000
1000 rows successfully bulk-copied to host-file. Total received: 3000
1000 rows successfully bulk-copied to host-file. Total received: 4000
1000 rows successfully bulk-copied to host-file. Total received: 5000
1000 rows successfully bulk-copied to host-file. Total received: 6000
1000 rows successfully bulk-copied to host-file. Total received: 7000
1000 rows successfully bulk-copied to host-file. Total received: 8000
1000 rows successfully bulk-copied to host-file. Total received: 9000
1000 rows successfully bulk-copied to host-file. Total received: 10000
1000 rows successfully bulk-copied to host-file. Total received: 11000
1000 rows successfully bulk-copied to host-file. Total received: 12000
1000 rows successfully bulk-copied to host-file. Total received: 13000
1000 rows successfully bulk-copied to host-file. Total received: 14000
1000 rows successfully bulk-copied to host-file. Total received: 15000
1000 rows successfully bulk-copied to host-file. Total received: 16000
1000 rows successfully bulk-copied to host-file. Total received: 17000
1000 rows successfully bulk-copied to host-file. Total received: 18000
1000 rows successfully bulk-copied to host-file. Total received: 19000
1000 rows successfully bulk-copied to host-file. Total received: 20000
1000 rows successfully bulk-copied to host-file. Total received: 21000
1000 rows successfully bulk-copied to host-file. Total received: 22000
我尝试使用bcp out 传递-b 开关,但它总是以1000 个为一组导出它们,并且通过greping 或seding 过滤行将花费太多时间。
感谢您的帮助。
【问题讨论】:
-
我不确定这里的问题是什么。您的 BCP 是否无法正常工作,或者您是否尝试在 BCP 输出消息中查看某些数据需要查看?
-
我想减少此类行
1000 rows successfully bulk-copied to host-file. Total received: 2000的出现,因为我们将 bcp 的输出记录在一个文件中,并且在某些情况下有数百万行,因此日志文件变得非常大,我想在不影响 bcp 性能的情况下减小日志文件的大小。 -
好的,这就澄清了。不确定是否有可能……祝你好运。
-
这是
bcp的新成员吗?我在 linux 机器上使用bcp时遇到了同样的问题,但我在使用bcp且不产生此输出的旧服务器(仅一年)上有另一个进程。两者都使用linux centos7。
标签: sql-server-2008 export-to-csv bcp