啓用 xp_cmdshellshell
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 表示按字符類型輸出;spa
-t 「,」 用逗號分隔get