sql server的bcp指令

有时需要允许bcp指令

-- 允许配置高级选项
EXEC sp_configure 'show advanced options', 1
GO
-- 重新配置
RECONFIGURE
GO
-- 启用xp_cmdshell
EXEC sp_configure 'xp_cmdshell', 1
GO
--重新配置
RECONFIGURE
GO

1、导出文件:

  EXEC ('EXEC master..xp_cmdshell ''bcp "select * from [dbname].[dbo].tablename where xx=''''xx'''' " 

queryout "D:\sql\.txt" -c -S"QCLOUD-VM" -U"username" -P"pwd"''')

2、导入文件:

  exec master..xp_cmdshell 'bcp [dbname].[dbo].tablename in d:\sql\sql.txt -c -T'

posted @ 2017-01-17 18:20  随缘梦中人  阅读(562)  评论(0编辑  收藏  举报