日期:2014-05-17  浏览次数:20442 次

bcp如何导出导入远程服务器数据到本地机的一个文件里
最近在研究 使用sql语句将远程数据库数据根据筛选条件导出到本地机的一个文件里,上网找到了BCP 但是使用BCP本地机上可以连接到 服务器就出现问题了,貌似使用bcp导服务器上的数据是将数据到出到服务器上了没导出到本地机,求高手们指教如何使用bcp将服务器上的数据导出到本地机呢?或者是有什么方法不使用bcp只通过sql语句将服务器数据导出到本地机!!急需  求高手 啊  !!服务器是 sqlserver 2008 的

------解决方案--------------------
下面的方法可以直接导出到.txt文件

-- To allow advanced options to be changed.
EXEC sp_configure 'show advanced options', 1
GO
-- To update the currently configured value for advanced options.
RECONFIGURE
GO
-- To enable the feature.
EXEC sp_configure 'xp_cmdshell', 1
GO
-- To update the currently configured value for this feature.
RECONFIGURE
GO

EXEC sp_configure 'xp_cmdshell', 1
GO

EXEC master..xp_cmdshell 'bcp "SELECT top 100 * FROM 数据库名.dbo.表名" queryout "d:\1.txt" -c -t \t -S"localhost\sqlexpress" -U"sa" -P"12345" '