BCP数据表备份

本文介绍SQL Server中的BCP命令行工具,用于高效导入导出大量数据。包含基本使用方法、条件筛选及混合模式身份验证等高级用法,并提供解决常见问题的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

(注意点:以下文字中涉及的bcp的命令不可以换行)

BCP命令:BCP是SQL Server中负责导入导出数据的一个命令行工具,能以并行的方式高效地导入导出大批量的数据。BCP可以将数据库的表或视图直接导出,也能通过SELECT FROM语句对表或视图进行过滤后导出。

BCP数据表备份:

--备份数据表

EXEC master..xp_cmdshell

'bcp ylzc_gyl_20180903.dbo.Adm_Authority  out D:\新建文本文档.dat -T -c'

--带条件的数据表备份

EXEC master..xp_cmdshell

'bcp "SELECT * FROM ylzc_gyl_20180903.dbo.Adm_Authority WHERE AuthID=''ea222ef5-cffd-45b4-a990-e85cfe351988''" queryout D:\新建文本文档4.dat -T -c'

--混合模式身份验证

EXEC master..xp_cmdshell

'bcp ylzc_gyl_20180903.dbo.Adm_Authority out D:\新建文本文档.txt -c -Usa -P123456 -S.'

--本地文件写入数据表中(Adm_Authority_BCP_IN先创建好表结构,再导入数据)

EXEC master..xp_cmdshell

'bcp ylzc_gyl_20180903.dbo.Adm_Authority_BCP_IN in D:\新建文本文档.dat -T -c'

--加上权限

sp_configure 'show advanced options',1 

reconfigure

go

sp_configure 'xp_cmdshell',1

reconfigure

go

--去掉权限

sp_configure 'show advanced options',1

reconfigure

go

sp_configure 'xp_cmdshell',0

reconfigure

go

操作过程中遇到的问题如下:

错误:EXEC master..xp_cmdshell

'bcp ylzc_gyl_20180903.dbo.Adm_Authority  out D:\新建文本文档.txt -T -c'

解决方案:加上权限

sys.sp_configure 'show advanced options',1

reconfigure

go

sp_configure 'xp_cmdshell',1

reconfigure

go

去掉权限:

sp_configure 'show advanced options',1

reconfigure

go

sp_configure 'xp_cmdshell',0

reconfigure

Go

错误2:

解决方案:sql server management studio 右键管理员运行。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值