sql 将表导出到Txt / CSV文件

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql 将表导出到Txt / CSV文件相关的知识,希望对你有一定的参考价值。

/*Only works if you are the destination folder
is on the database server hard drive. I.e., if attempting to execute this from blofeld, you need to remote into blofeld and create the destination.
Reference :  http://craftydba.com/?p=1690
*/

/* BCP - Export whole table, txt format, trusted security, character format */
DECLARE @bcp_cmd1 VARCHAR(1000);
DECLARE @exe_path1 VARCHAR(200) = 
    ' cd C:\Program Files\Microsoft SQL Server\100\Tools\Binn\ & ';
SET @bcp_cmd1 = @exe_path1 + 
    ' BCP.EXE stuart_sandbox.dbo.dealers out ' +
    'C:\temp\exportTest\dealerExport.csv -T -c ';
PRINT @bcp_cmd1;
EXEC master..xp_cmdshell @bcp_cmd1;
GO

以上是关于sql 将表导出到Txt / CSV文件的主要内容,如果未能解决你的问题,请参考以下文章