1.在执行bcp命令时,可能没有权限,需要先打开权限如下
use master
go
sp_configure 'show advanced options',1
reconfigure
go
sp_configure 'xp_cmdshell',1
reconfigure
go
关闭权限如下:
exec sp_configure 'Ad Hoc Distributed Queries',0
reconfigure
exec sp_configure 'show advanced options',0
reconfigure
2.如果还有问题,设置路径,要查看bcp.exe是否已经添加到环境变量中,使系统能找到执行路径。
1)在sqlserver安装目录中找到bcp.exe,目录:C:\Program Files\Microsoft SQL Server\100\Tools\Binn
2)添加环境变量,path中加入:C:\Program Files\Microsoft SQL Server\100\Tools\Binn
3.执行导出命令
EXEC xp_cmdshell 'BCP "select * from Tables.dbo.Meter_T" queryout d:\tset1.txt -c -U"sa" -P"123456"'
解说:1)xp_cmdshell 系统存储过程
2)-U"sa" -P"123456"'登录sqlserver用户名和密码
本文详细介绍了在 SQL Server 中使用 BCP 命令进行数据导入导出的方法,包括解决权限问题、配置环境变量及具体的执行命令等步骤。
381

被折叠的 条评论
为什么被折叠?



