bcp 的一般用法

bcp 的一般用法 

用法: bcp {dbtable | query} {in | out | queryout | format} 数据文件

  [-m 最大错误数]             [-f 格式化文件]         [-e 错误文件]
  [-F 首行]                   [-L 末行]             [-b 批大小]
  [-n 本机类型]               [-c 字符类型]         [-w 宽字符类型]
  [-N 将非文本保持为本机类型] [-V 文件格式版本]     [-q 带引号的标识符]
  [-C 代码页说明符]           [-t 字段终止符]       [-r 行终止符]
  [-i 输入文件]               [-o 输出文件]         [-a 数据包大小]
  [-S 服务器名称]             [-U 用户名]           [-P 密码]
  [-T 可信连接]               [-v 版本]             [-R 允许使用区域设置]
  [-k 保留空值]               [-E 保留标识值]
  [-h"加载提示"]              [-x 生成xml 格式化文件]
导入csv格式文件
Exec master..xp_cmdshell 'bcp "SSIS.dbo.tb2" in "E:\export.csv" -c -t"," -r"\n" -T'
导出成csv
Exec master..xp_cmdshell 'bcp "SSIS.dbo.tb2" out "E:\test.csv" -c -t"," -r"\n" -T'
将特定查询导出成默认格式
默认以制表符间隔,"\n"换行
Exec master..xp_cmdshell 'bcp "select carbrand,longitude from ssis.dbo.tb2" queryout "E:\test2.txt" -c -T'
其他情况参考:http://msdn.microsoft.com/zh-cn/library/ms162802.aspx
启用xp_cmdshell
EXEC sp_configure 'show advanced options', 1 
GO 
RECONFIGURE 
GO 
EXEC sp_configure 'xp_cmdshell', 1 
GO 
RECONFIGURE 
GO 
原文地址:https://www.cnblogs.com/stublue/p/2581300.html