BCP导入导出MsSql

1、导出数据

(1)、在Sql Server Management Studio中:

--导出数据到tset1.txt,并指定本地数据库的用户名和密码
--这里需要指定数据库完全限定名。
--username 数据登录名
--password 数据库密码
EXEC master..xp_cmdshell 'BCP "SELECT * FROM Testdb.dbo.TestVoucher" queryout d:	set1.txt -c -U"username" -P"password"'

注:SQL Server阻止了对组件xp_cmdshell过程的解决方案

sp_configure 'show advanced options',1
reconfigure
go
sp_configure 'xp_cmdshell',1
reconfigure
go

(2)、在CMD中

BCP "SELECT * FROM Testdb.dbo.TestVoucher" queryout d:	set1.txt -c -S"服务器地址" -U"username" -P"password"

如图:

2、导入数据

(1)、在Sql Server Management Studio中:

 EXEC master..xp_cmdshell 'bcp Testdb.dbo.TestVoucher  in d:	set1.txt -c -T' 

(2)、在CMD中

bcp Testdb.dbo.TestVoucher  in d:	set1.txt -c -T

图:

原文地址:https://www.cnblogs.com/xdpxyxy/p/3199726.html