启用 xp_cmdshell

  1: sp_configure 'show advanced options',1
  2: reconfigure
  3: GO
  4: 
  5: sp_configure 'xp_cmdshell',1
  6: reconfigure
  7: go
  8: 

BCP测试

  1:    
  2:    --建立文件夹
  3:    DECLARE  @CmdLine VARCHAR(500)=' md E:\NetworkOptFtpServer'
  4:    PRINT @CmdLine
  5:    EXEC master.. xp_cmdshell @CmdLine
  6:    
  7:    --生成文件 
  8:    SET  @CmdLine  = 'bcp " SELECT  * FROM table  " queryout  E:\NetworkOptFtpServer\test_in.csv -w -U sa  -P xxxx '
  9:    PRINT @CmdLine
 10:    EXEC master.. xp_cmdshell @CmdLine

指定编码格式

  1: exec master..xp_cmdshell
  2: 'bcp "SELECT * FROM tablename" queryout "C:\test.txt" -T -c -C 65001'


最后的参数 -T 表示这是信任的连接,也就是说不用输入密码了;-c 表示按字符类型输出;

-t “,” 用逗号分隔

相关文章:

  • 2022-12-23
  • 2022-02-16
  • 2022-12-23
  • 2021-09-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-07
  • 2021-06-15
相关资源
相似解决方案