BCP導入導出MsSql

一、導出數據

(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過程的解決方案shell

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"

如圖:數據庫

二、導入數據

(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

圖:服務器

相關文章
相關標籤/搜索