【发布时间】:2014-04-17 19:35:19
【问题描述】:
我有一个包含数千行的表,在名为 OldValue 的列中包含以下数据:
<attendance xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<CalendarId>100</CalendarId>
<PeriodId>1019</PeriodId>
<PersonId>10457</PersonId>
<Date>2012-01-04 00:00:00</Date>
<ExcuseId>884</ExcuseId>
</attendance>
我正在尝试设置选择性 xml 索引。这是我到目前为止所做的:
创建选择性 XML 索引:
CREATE SELECTIVE XML INDEX sxi_Test ON [dbo].[mytable](OldValue)
WITH XMLNAMESPACES ('http://www.w3.org/2001/XMLSchema-instance' as yming)
FOR
(
pathWH2 = '/yming:Attendance/PersonId' AS XQUERY 'xs:string' SINGLETON
);
GO
查询索引总是返回0行:
WITH XMLNAMESPACES ('http://www.w3.org/2001/XMLSchema-instance' as yming)
SELECT COUNT(*)
FROM mytable
WHERE OldValue.exist(N'(/yming:Attendance/yming:PersonId[.=10457])') = 1
GO
有什么建议吗?谢谢。
【问题讨论】:
标签: sql sql-server xml indexing