sql SQL Server中的XML索引,主要和辅助

Posted

tags:

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

/*
Each time an XQuery expression is used in SQL Server, SQL Server creates a nodes tree for each query and has to read it, which has overhead implications. XML indexes can help improve performance by creating a pre-defined node tree. Indexes contain details of:

- nodes
- values
- paths
*/

-- A Primary XML index provides a persisted node tree in an internal format that is used to speed access to elements and attributes within the XML. It requires a clusted primary key on the table in the first place.
CREATE PRIMARY XML INDEX XML_Order_Items
ON Sales.Order (Items);

/*
A Secondary XML index is one that supports XQuery expressions. They can only be created after a Primary XML index has been created. You can create three types of secondary indexes to help resolve specific XQuery expressions rapidly. You can have multiple secondary XML indexes, including having one for Property, one for Value, and one for Path:

- PROPERTY - optimized for retreiving multiple values in query method calls
- VALUE - optimized for retrieving single values in value method calls
- PATH - typeically used by the exist method
*/

CREATE XML INDEX XML_Order_Items_Path
ON Sales.Order (Items)
USING XML INDEX XML_Order_Items FOR PATH;
GO

CREATE XML INDEX XML_Order_Items_Value
ON Sales.Order (Items)
USING XML INDEX XML_Order_Items FOR VALUE;
GO

CREATE XML INDEX XML_Order_Items_Property
ON Sales.Order (Items)
USING XML INDEX XML_Order_Items FOR PROPERTY;
GO

以上是关于sql SQL Server中的XML索引,主要和辅助的主要内容,如果未能解决你的问题,请参考以下文章

Sql Server XML 列替代 Document DB?

SP 执行时 SQL Server 2008 中的 QUOTED IDENTIFIER 错误

SQL Server 创建索引(index)

SQL Server 创建索引(index)

SQL Server 创建索引(index)

使用SQL Server XML Import添加索引