SQL Server BCP 的数据导入导出
2 }$ f3 A; z, s3 ?- o7 ]/** 导入文本文件 / O6 l, S" l/ R7 g4 a
EXEC master..xp_cmdshell ’bcp "dbname..tablename" in c:\DT.txt -c -Sservername -Usa -Ppassword’ 5 u" `2 r' a9 U5 X+ a, B/ o0 S; W
/** 导出文本文件
+ t% H& @+ m/ i+ C0 L6 _. C6 _EXEC master..xp_cmdshell ’bcp "dbname..tablename" out c:\DT.txt -c -Sservername -Usa -Ppassword’
: p2 K# k' |0 h1 B/ p或
4 Y3 t- ^& V. Y [EXEC master..xp_cmdshell ’bcp "Select * from dbname..tablename" queryout c:\DT.txt -c -Sservername -Usa -Ppassword’ 3 s$ K1 b4 s1 b9 [8 h' I
7 q- }* I4 C* E7 A) ^2 u: K' g7 W. {
' ^4 X" s$ m7 ?/ {5 P$ F( [' w: |, i j& r( `# N
SQL2000中BCP轻松使用导入导出数据" P7 L0 g! c7 x3 I& `
bcp 可以实现数据的导入与导出。
5 ^2 J! N4 ^, T1 ?, u% n" }0 z% H8 s; Z; _5 V
c:\>bcp "demo.dbo.订单表" out "c:\test.txt" -c -q -S "virus\mysql" -U "sa"0 |' X1 b0 P& l/ A# h& }, l
-P "dir"6 f. x! @( Z( K/ D( y g
9 d. s O) n9 r注释:demo.dbo.订单表 把demo里面表订单表导出& b2 M+ u% O. a, j q) {/ K6 I
out 导出) d5 l/ ~6 @) j+ H: j; i( O
in 导入
% W$ t% q h, x -c 和-q 指定导出时按规则排序
/ f% |+ q) c* X; E; P- R2 X -S "virus\mysql" 指定Server名称为virus实例名为mysql
1 B7 V- p' Q" Z -U “sa” 指定用户SA8 y& |8 e& W( [' a- B) p3 T) P& a2 N& h
-P “dir” 密码是dir |