导出前先要设置配置信息:
exec sp_configure 'show advanced options',1
RECONFIGURE
exec sp_configure 'xp_cmdshell',1
RECONFIGURE
exec sp_configure 'show advanced options',1
RECONFIGURE
exec sp_configure 'xp_cmdshell',1
RECONFIGURE
整个表导出txt
EXEC master..xp_cmdshell 'bcp "database.dbo.table" out f:/DT1.txt -c -U"sa" -P"123"'
查询导出txt
EXEC master..xp_cmdshell 'bcp "SELECT * from database.dbo.table" queryout f:/cc.TXT -c -U"sa" -P"123"'