sqlserver 用 bcp 導表數據

/*sql

一、使用bcp 須要先開啓 xp_cmdshellshell

二、bcp 導出導入只需更改  命令  out/inwindows

三、支持可信鏈接既windows驗證和 sa 的驗證server

eg : -n -t -S"servername"  -T         |   -c -n -U"sa"  -P"123"cmd

四、若導帶sql語句的,須要跟 queryout 配合使用io

 bcp "select * from test where userid>500" queryout d:test.csv -c -ttable

*/ast

-- 容許配置高級選項  
EXEC master.sys.sp_configure 'show advanced options', 1  
-- 從新配置  
RECONFIGURE  
-- 啓用xp_cmdshell  
EXEC master.sys.sp_configure 'xp_cmdshell', 1  
--從新配置  
RECONFIGUREtest

EXEC master..xp_cmdshell 'BCP  dbname.dbo.tablename out d:\tablename.csv -n -t -S"127.0.0.1,2433" -T'dva

-- 容許配置高級選項

EXEC sp_configure 'show advanced options', 1

-- 從新配置

RECONFIGURE

-- 禁用xp_cmdshell

EXEC sp_configure 'xp_cmdshell', 0

--從新配置

RECONFIGURE

--完成關閉

相關文章
相關標籤/搜索