是否可以在SQL Server 2005 / SQL Server 2008上的XML列中设置索引? [英] Is it possible to set an index inside a XML column on SQL Server 2005 / SQL Server 2008?

查看:124
本文介绍了是否可以在SQL Server 2005 / SQL Server 2008上的XML列中设置索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序将xml文档存储在SQL Server的列中。 XML文档的结构类似于下面的结构:

I have an application that stores xml documents inside a column on SQL Server. The structure of the XML document is similar to the one below:

<document>
    <item>
        ...
        <phoneNumber>0123456789</phoneNumber>
        ....
    </item>
    <item>
        ...
        <phoneNumber>9876543210</phoneNumber>
        ....
    </item>
    ...
</document>

此列基本上存储了一组客户信息。 XML文档可以在< item>内部具有不同的子元素。但是,其中一些子元素包含在所有文档中(例如上例中的< phoneNumber>元素)。

Basically this column stores a set of customer information. The XML documents can have different child elements inside the <item> element, nevertheless some of these child elements are contained in all documents (e.g. the <phoneNumber> element in the above example).

这样我可以有例如,表格中包含以下值的一行

This way I can have for example, one row in the table containing the following value

<document>
    <item>
        <firstName>Carlos</firstName>
        <lastName>Loth</lastName>
        <phoneNumber>0123456789</phoneNumber>
    </item>
    <item>
        <firstName>Alberto</firstName>
        <lastName>Tomatis</lastName>
        <phoneNumber>987654321</phoneNumber>
    </item>
</document>

另一行包含此文件

<document>
    <item>
        <orderNumber>XYZ</orderNumber>
        <phoneNumber>0123456789</phoneNumber>
    </item>
    <item>
        <orderNumber>ABC</orderNumber>
        <phoneNumber>987654321</phoneNumber>
    </item>
</document>

所以,我的问题是,是否可以根据文档在该XML列上创建索引/ item / phoneNumber元素?我需要执行一个查询,根据phoneNumber信息返回存储在其他固定已知列中的信息。

So, my question is that is it possible to create an index on that XML column based on the document/item/phoneNumber element? I need to perform a query that returns the information stored in other "fixed known" columns based on the phoneNumber information.

任何建议或想法?

提前致谢,
Carlos Loth。

Thanks in advance, Carlos Loth.

推荐答案

是。

SQL Server 2005支持四种不同类型的XML索引。由于XML索引与关系索引略有不同,因此在我们研究如何使用它们以获得最大效率之前,有必要了解它们的实现。有一个主XML索引和三种不同风格的二级XML索引。

Yes.
SQL Server 2005 supports four different types of XML indexes. Since an XML index is somewhat different than a relational index, it is necessary to know their implementation before we approach how to use them for maximum effectiveness. There is a single "primary XML index" and three different flavors of "secondary XML index".

有关详细信息,请参阅此MSDN文章

For more info, see this MSDN article

您需要先创建主XML索引,然后才能定义辅助XML索引:

You need to create a primary XML index before you can define secondary XML indexes:

CREATE PRIMARY XML INDEX xml_idx ON your_table(xml_column)
CREATE XML INDEX xml_idx ON your_table(xml_column) FOR PROPERTY

创建XML索引文档

这篇关于是否可以在SQL Server 2005 / SQL Server 2008上的XML列中设置索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆