且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将 SQL 查询结果保存到磁盘上的 XML 文件

更新时间:2022-01-30 21:58:49

您还可以将 SQL Server 的扩展存储过程导出为 xml 文件.

You can also your SQL Server's extended stored procedures to export it to an xml file.

但是您需要先配置 sql server 才能使用它.

But you would need to configure the sql server before you can use it.

EXEC master.dbo.sp_configure 'show advanced options', 1
RECONFIGURE
EXEC master.dbo.sp_configure 'xp_cmdshell', 1
RECONFIGURE

一旦在 SQL Server 中启用了 xp_cmdshel.您可以使用以下命令将数据导出到 xml 文件.

Once xp_cmdshel is enabled in the SQL Server. You can use the following command to export the data to an xml file.

EXEC xp_cmdshell 'bcp "SELECT [Created], [Text] FROM [db304].[dbo].[SearchHistory] FOR XML PATH(''Record''), ROOT(''SearchHistory'')" queryout "C:\bcptest.xml" -T -c -t,'