惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

量子位
S
Securelist
MyScale Blog
MyScale Blog
Jina AI
Jina AI
罗磊的独立博客
The Cloudflare Blog
美团技术团队
博客园 - 叶小钗
阮一峰的网络日志
阮一峰的网络日志
博客园 - 三生石上(FineUI控件)
月光博客
月光博客
雷峰网
雷峰网
小众软件
小众软件
aimingoo的专栏
aimingoo的专栏
大猫的无限游戏
大猫的无限游戏
博客园 - Franky
博客园 - 聂微东
Y
Y Combinator Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
MongoDB | Blog
MongoDB | Blog
T
Tailwind CSS Blog
Attack and Defense Labs
Attack and Defense Labs
博客园_首页
Latest news
Latest news
Apple Machine Learning Research
Apple Machine Learning Research
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
The Hacker News
The Hacker News
G
GRAHAM CLULEY
Simon Willison's Weblog
Simon Willison's Weblog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Proofpoint News Feed
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
U
Unit 42
D
Docker
Webroot Blog
Webroot Blog
N
Netflix TechBlog - Medium
T
Tor Project blog
C
Cyber Attacks, Cyber Crime and Cyber Security
L
LINUX DO - 最新话题
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
The Last Watchdog
The Last Watchdog
B
Blog
Recent Announcements
Recent Announcements
GbyAI
GbyAI
Microsoft Azure Blog
Microsoft Azure Blog
Security Latest
Security Latest
V2EX - 技术
V2EX - 技术
N
News | PayPal Newsroom
Microsoft Security Blog
Microsoft Security Blog

博客园 - GDLMO

给12306的建议 在delphi中引用第三方控件时,找不到dcu的解决办法 使用SqlBulkCopy时应注意Sqlserver表中使用缺省值的列 无法识别的属性“requirePermission” sqlserver,将视图或表的记录不重复的插入到另一个表 让单元测试项目也能同步测试主程序的APP.CONFIG 水平太差,虽然认为Linq是个好东东,但有谁能教教我,怎么调试? Sqlserver 插入一条记录时,不重复插入的办法 dnn5.5.1的配置 动态生成ASP.NET按钮时要注意的一个问题 关于EditUrl与NavigateURL的调用问题 DNN常用的几种页面跳转(EditUrl和Globals.NavigateURL) The Auto option has been disabled as the DotNetNuke Application cannot connect to a valid SQL Server database SQLite3中TimeStamp的使用问题 博文阅读密码验证 - 博客园 在DNN中使用SqlDataReader ExecuteReader(string connectionString, string spName, params object[] parameterValues)始终无法获得返回值 在DNN中使用jQuery的插件Validate Enter Null Values for DateTime Column of SQL Server(转) Web.Config和Sql Server2005连接字符串总结(转)
在sqlserver中使用bcp自动导出数据的方法和注意事项
GDLMO · 2012-06-25 · via 博客园 - GDLMO

今天测试了下sqlserver中BCP导出数据的功能,可以在sqlserver studio中的查询窗口中使用,也可以在命令行中使用。

方法1:在查询窗口中使用。在查询窗口中使用必需通过sp_configure打开xp_cmdshell的运行许可

sp_configure设置打开xp_cmdshell的脚本

 1 -- To allow advanced options to be changed.
 2 EXEC sp_configure 'show advanced options'1
 3 GO
 4 -- To update the currently configured value for advanced options.
 5 RECONFIGURE
 6 GO
 7 -- To enable the feature.
 8 EXEC sp_configure 'xp_cmdshell'1
 9 GO
10 -- To update the currently configured value for this feature.
11 RECONFIGURE
12 GO

 在打开xp_cmdshell的运行许可后,可以运行如下(设表库为test,表为 ryxx)

在查询窗口中导出数据,使用“用户名及密码的方式”

1 EXEC master..xp_cmdshell 'bcp test.dbo.ryxx out c:\currency1.txt -c -U"用户名" -P"密码"'

以可信连接方式

1 EXEC master..xp_cmdshell 'bcp test.dbo.ryxx out c:\currency1.txt -c -T'

 注意:在查询窗口中执行时可能会出现如下的错误(如下图1所示),这是因为没有对目录添加读写权限造成的,我将输出目录改为“d:\temp”,并添加了NETWORK SERVICE的读写权限(如图2所示),问题解决

bcp在查询窗口执行的错误

图1

给目录添加读写权限

图2

方法2:在命令行中导出,首先bcp的执行程序位于 “C:\Program Files\Microsoft SQL Server\100\Tools\Binn\"

以可信连接方式

bcp test.dbo.ryxx out c:\currency1.txt --T

以用户名密码方式

1 bcp test.dbo.ryxx out c:\currency1.txt --U"用户名" -P"密码"

 注意,表名最好是没有特殊字符和“-”的字符串,我的表名为2012-06-25时提示出错。