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

--完成关闭

相关文章
相关标签/搜索