1.首先需要启用xp_cmdshell组件:
sp_configure 'show advanced options',1
reconfigure
go
sp_configure 'xp_cmdshell',1
reconfigure
go
2.测试导出:
结果:
多种写法:
exec master..xp_cmdshell 'bcp "select * From Test.dbo.Class" queryout E:\Class.txt -T -c'
3、导入:
exec master..xp_cmdshell 'bcp Test.dbo.Class in E:\Class.txt -T -c
总结:如果表数据比较杂乱,导入可能会有一些报错,建议制定 列分隔符 -t 指令。
详细bcp 命令解析: bcp {dbtable | query