/*
1、使用bcp 需要先开启 xp_cmdshell
2、bcp 导出导入只需更改 命令 out/in
3、支持可信连接既windows验证和 sa 的验证
eg : -n -t -S"servername" -T | -c -n -U"sa" -P"123"
4、若导带sql语句的,需要跟 queryout 配合使用
bcp "select * from test where userid>500" queryout d:test.csv -c -t
*/
-- 允许配置高级选项
EXEC master.sys.sp_configure 'show advanced options', 1
-- 重新配置
RECONFIGURE
-- 启用xp_cmdshell
EXEC master.sys.sp_configure 'xp_cmdshell', 1
--重新配置
RECONFIGURE
EXEC master..xp_cmdshell 'BCP dbname.dbo.tablename out d:\tablename.csv -n -t -S"127.0.0.1,2433" -T'
-- 允许配置高级选项
EXEC sp_configure 'show advanced options', 1
-- 重新配置
RECONFIGURE
-- 禁用xp_cmdshell
EXEC sp_configure 'xp_cmdshell', 0
--重新配置
RECONFIGURE
--完成关闭