sql-server-2008 - 减少 bcp export 的输出

标签 sql-server-2008 export-to-csv bcp

在我们的项目中,我们使用 bcp 命令导出大约数百万行并将输出记录到输出文件中。
对于 bcp 导入,我可以控制 bcp 的输出使用 -b 命令指定编号的开关。要批量导入的行数。输出是这样的:

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

我试过通过 -bbcp out 切换但它总是以 1000 为一组导出它们并通过 greping 过滤行或 seding他们将花费太多时间。
谢谢你的帮助。

最佳答案

在 bcp 中似乎没有解决方案。但是,有一种解决方法;将 bcp 命令行打包到 xp_cmdshell 语句中并指定 no_output 选项:

EXEC xp_cmdshell "bcp  Temp.dbo.TestTable out outdata.txt -t , -f file.fmt -S Server -U user-P password -m 10", no_output

来源:click here

关于sql-server-2008 - 减少 bcp export 的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19447085/

相关文章:

sql-server - 如何对身份列使用 bcp?

sql-server - SQL Server 执行 xp_cmdshell 通过 FTP 协议(protocol)从 UNIX 机器导入文本文件

SQL Server 2008 选择由变量定义的前 100 个

sql - 与所有列进行比较

sql-server-2008 - 无法在 SQL Server 2008 R2 中使用 OPENROWSET 导入到 Excel

hadoop - 如何将数据从 Spark SQL 导出到 CSV

sql-server - Sql Bulk insert XML格式文件,终止符中带双引号

sql - 如何从类型创建临时表?

java - 在java中使用CSVWriter写入CSV时删除空格

c# - 如何从内存流中获取所有数据到 CSV?