简体   繁体   English

如何将SQL Server表数据作为插入命令导出到文本文件?

[英]How to export SQL Server table data into text file as Insert command?

I have a table with bulk data (say 2 Million rows). 我有一个包含批量数据的表(例如200万行)。 I need to export this data into a text file. 我需要将此数据导出到文本文件中。

I've approached Generate Scripts method by which it throws 我已经接触了它引发的Generate Scripts方法

System.OutOfMemoryExeception. System.OutOfMemoryExeception。

I need to some how convert the data into text file. 我需要一些如何将数据转换为文本文件。 Can sqlcmd approach be helpful? sqlcmd方法会有所帮助吗? If so please suggest the steps. 如果是这样,请建议步骤。

Turn on xp_cmdshell in Facets and run this - Facets打开xp_cmdshell并运行它-

DECLARE @sql NVARCHAR(4000) = 'bcp "SELECT * FROM sys.schemas" queryout "D:\sample.txt" -S ' + @@servername + ' -T -w -r -t'
EXEC sys.xp_cmdshell @sql

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM