命令导入导出sqlserver 数据

前提:需要启用BCP命令,这个要在SqlServer 命令窗口执行

--允许配置高级选项
exec sp_configure 'show advanced options',1
go
--重新配置
reconfigure
go
--启用xp_cmdshell
exec sp_configure 'xp_cmdshell',1
go

 

1. 导出表结构:

bcp 数据库名称.dbo.表名 format nul -f c:\表名.Table.fmt.xml -x -c -S "(local)" -U "sa" -P "123"

 

2  导出数据表文本内容:

bcp 数据库名称.dbo.表名 out c:\表名.Data.sql -c -k -S "(local)" -U "sa" -P "123"

3  导入数据:
bulk insert 数据库名称.dbo.表名 
FROM 'c:\表名.Data.sql'
with
(
FORMATFILE = 'c:\表名.Table.fmt.xml'
)

导入数据前,记得先建好表结构。

 

参考:https://codeleading.com/article/52801682971/

 

posted @ 2024-01-17 17:29  along_bro  阅读(46)  评论(0编辑  收藏  举报