【发布时间】:2013-11-25 05:47:47
【问题描述】:
我有一个带有 xml 列的 sql 表,其中包含如下 xml 的值
<Security xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Dacl>
<ACEInformation>
<UserName>Authenticated Users</UserName>
<Access>Allow</Access>
<IsInherited>false</IsInherited>
<ApplyTo>This object only</ApplyTo>
<Permission>List Contents</Permission>
<Permission>Read All Properties</Permission>
<Permission>Read Permissions</Permission>
</ACEInformation>
<ACEInformation>
<UserName>Administrator</UserName>
<Access>Allow</Access>
<IsInherited>false</IsInherited>
<ApplyTo>This object only</ApplyTo>
<Permission>Read All Properties</Permission>
<Permission>Delete</Permission>
</ACEInformation>
<ACEInformation>
<UserName>Admin2</UserName>
<Access>Allow</Access>
<IsInherited>false</IsInherited>
<ApplyTo>This object only</ApplyTo>
<Permission>Read All Properties</Permission>
<Permission>Delete</Permission>
</ACEInformation>
</Dacl>
</Security>
我的需要是,我必须查询所有具有 Access: Allow 和 Permission: Delete 值的 UserName 值。为此,我正在使用以下 XQuery。
Select xmlColumn.query('for $item in (/Security/Dacl/ACEInformation[Access="Allow"][Permission="Delete"]/UserName) return concat($item,";")').value('.','NVARCHAR(MAX)') from myTable
返回值:Administrator;Admin2 用于上述 xml。查询工作正常...但性能非常低,1000 行需要 1 分钟。
你能为这种情况提供最好的 xquery 吗?
【问题讨论】:
标签: sql sql-server xquery sqlxml xquery-sql