In this article, we’ll show how to create an XML data type document from a relational table utilizing different T-SQL ways. For example, for data migration, information from the SQL Server database can be exported and imported using XML in another framework. XML is a standard way of extracting, storing and manipulating data. One aspect of working with the XML data type is creating XML from relational information, which is done using the FOR XML provision in SQL Server:
在本文中,我们将展示如何使用不同的T-SQL方法从关系表中创建XML数据类型文档。 例如,对于数据迁移,可以在另一个框架中使用XML导出和导入SQL Server数据库中的信息。 XML是提取,存储和处理数据的标准方法。 使用XML数据类型的一个方面是根据关系信息创建XML,这是使用SQL Server中的FOR XML设置完成的:
An XML data type can be utilized in an alternate manner in SQL Server. This article will explain some fundamental uses of XML. FOR XML keyword is a provision that can be added with the SELECT query statement to prepare the XML document in the required forms in a query result. The outcome is a Unicode string containing components and qualities controlled by the different modes determined in the provision with FOR XML.
XML数据类型可以在SQL Server中以替代方式使用。 本文将解释XML的一些基本用法。 FOR XML关键字是一项规定,可以与SELECT查询语句一起添加以在查询结果中按要求的形式准备XML文档。 结果是一个Unicode字符串,其中包含由FOR XML规定中确定的不同模式控制的组件和质量。
The four modes are:
四种模式是:
- RAW 生的
- AUTO 汽车
- EXPLICIT 显式
- PATH 路径
The table below shows sample data for further clarification of the various methodologies:
下表显示了样本数据,用于进一步阐明各种方法:
自动模式 (AUTO mode)
AUTO mode is one of the approaches to converts over to the XML elements from the rows of the table. Element names of the XML document corresponding to the column alias or column name of the SELECT query.
AUTO模式是从表的行转换为XML元素的方法之一。 与SELECT查询的列别名或列名称相对应的XML文档的元素名称。
For example, the query result has been produced with a single XML document for the above sample data. The query result had 5 rows in a result set, which is changed over to a solitary