sql XML数据类型和在SQL Server中存储XML

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql XML数据类型和在SQL Server中存储XML相关的知识,希望对你有一定的参考价值。

-- XML is a native data type where you can place well-formed XML documents or XML fragments. The XML isn't stored as a literal string of XML, but is stored as a tree. When you query the XML back out, it rebuilds the XML into code that is semantically the same as what you put in, though there might be some differences (attributes in different orders, comments being lost, etc.).

-- example of how to create table that has an OrderItems column which will store XML, alongside the other columns which are normal relational data
CREATE TABLE #SalesOrder
(OrderID INT IDENTITY,
OrderDate DATETIME DEFAULT GETDATE(),
OrderItems XML);

-- example of how to insert XML into the OrderItems column. Note that this is XML fragment data, not an entire well-formed XML document
INSERT INTO SalesOrderTest (OrderItems)
VALUES
('<item id="561" quantity="1"> </item>
<item id="127" quantity="2"> </item>' );

以上是关于sql XML数据类型和在SQL Server中存储XML的主要内容,如果未能解决你的问题,请参考以下文章

SQL Server 对XML数据类型的SQL语句总结

SQL Server XML 数据类型

从SQL Server的XML数据类型字段中提取数据

处理 XML 数据类型(SQL SERVER 2005)

从 SQL Server 中的 XML 数据类型字段中提取数据

动态获取 SQL Server 中不同列中的 XML 数据类型值