Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to export data to XML and Json in SQL Server

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article shows you how to export data to XML and Json in SQL Server. The content is concise and easy to understand, which will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

Data export to XML

After SQL Server 2005, a for xml clause is provided to natively support XML in relational databases. With this command, the result set of 2D relationships can be converted to XML, and the data can be saved as XML through BCP.

For example, the following data:

We can export it to a XML file with the following BCP command (note that there is no enter) and save it:

The copy code is as follows: BCP "SELECT TOP 30 [bom_no], [LEVEL] FROM [sqladmin]. [dbo]. [bom] FOR XML path,TYPE, ELEMENTS, ROOT ('RegionSales')" QUERYOUT "d:\ temp\ test.XML"-c-t-T-S localhost

View the Test.XML file when the execution is complete, as shown in the following figure. You can see that the file format is so clear that it can be easily imported into other systems.

Data export to JSON

If you want to export data from SQL Server to Json, although there is a very mature way to do this in your application, SQL Server does not natively support this approach (grapevine, the next version will support it). I recommend using this post: / / www.xuebuyuan.com/article/61462.htm to do it. After the stored procedure provided by this post is established, use the following BCP command:

The above is how to export data to XML and Json in SQL Server. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report