--文本文件导出
EXEC Master..xp_cmdshell 'bcp "select * from sqbl.dbo.SubCenter" QueryOut "c: est.txt" /c /S"127.0.0.1" /U"sa" /P""'
--EXEC Master..xp_cmdshell 'bcp "查询" QueryOut "路径+文件名" /c /S"服务器名" /U"用户名" /P"密码"' 
--文本文件导入
EXEC Master..xp_cmdshell 'bcp "sqbl.dbo.SubCenter" In "c: est.txt" /c /S"127.0.0.1" /U"sa" /P""'
--EXEC Master..xp_cmdshell 'bcp "库名.dbo.表名" in "路径+文件名" /c /S"服务器名" /U"用户名" /P"密码"'
--导出到文本文件,自定制分隔符
EXEC Master..xp_cmdshell 'bcp "select * from sqbl.dbo.SubCenter" QueryOut "c: est.txt" /c /t";" /r" " /S"127.0.0.1" /U"sa" /P""'
--EXEC Master..xp_cmdshell 'bcp "查询" QueryOut "路径+文件名" /c /t"列分隔符" /r"行分隔符" /S"服务器名" /U"用户名" /P"密码"' 
--导入到文本文件,自定制分隔符
EXEC Master..xp_cmdshell 'bcp "sqbl.dbo.SubCenter" In "c: est.txt" /c /t";" /r" " /S"127.0.0.1" /U"sa" /P""'
--EXEC Master..xp_cmdshell 'bcp "库名.dbo.表名" in "路径+文件名" /c /t"列分隔符" /r"行分隔符" /S"服务器名" /U"用户名" /P"密码"'
select * from sqbl.dbo.SubCenter 
delete from sqbl.dbo.SubCenter 
--bcp具体参数请参见:
EXEC Master..xp_cmdshell 'bcp /?'
本文介绍如何使用 SQL Server 的 bcp 命令进行数据的导出与导入操作,包括基本语法及自定义分隔符的方法,并提供具体的示例。

695

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



