Fork me on GitHub
BCP导入导出MsSql

BCP导入导出MsSql

1、导出数据

(1)、在Sql Server Management Studio中:

--导出数据到tset1.txt,并指定本地数据库的用户名和密码
--这里需要指定数据库完全限定名。
--username 数据登录名
--password 数据库密码
EXEC master..xp_cmdshell 'BCP "SELECT * FROM Testdb.dbo.TestVoucher" queryout d:\tset1.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:\tset1.txt -c -S"服务器地址" -U"username" -P"password"

如图:

2、导入数据

(1)、在Sql Server Management Studio中:

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

(2)、在CMD中

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

图:

 
 
 
标签: 数据库
posted on 2013-07-19 11:11  HackerVirus  阅读(212)  评论(0编辑  收藏  举报