XML Shredding SQL Server性能

时间:2016-01-22 01:27:42

标签: sql sql-server xml sql-server-2008-r2

如果没有XML命名空间,我将如何解析下面的内容?

由于SQL Server 2008 R2,我遇到了超时问题,我打算使用查询提示OPTION ( OPTIMIZE FOR ( @xml = NULL ) )但不愿意。

如果您需要对查询进行更多说明,请通知我。感谢您的帮助。

DECLARE @i BIGINT , @rawxml XML

SELECT TOP 1 
    @i = prl.ID,
    @rawxml = prl.d
FROM
    s.dbo.l prl
WHERE 
    NOT EXISTS (SELECT 1
               FROM dbo.p
               WHERE id = prl.ID)
ORDER BY 
    prl.ID

;WITH XMLNAMESPACES ('http://xxx.xsd' AS pd)
INSERT INTO P (x, y)
    SELECT 
        rn = NULLIF(X.ps.value('(./@rn)[1]', 'varchar(25)'), '')
    FROM 
        @rawxml.nodes('/pd:ps/pd:p') AS X(ps)

1 个答案:

答案 0 :(得分:0)

尝试使用*

INSERT INTO dbo.p /*(...)*/
SELECT l.ID, NULLIF(t.c.value('@rn', 'VARCHAR(25)'), '')
FROM dbo.l l
CROSS APPLY d.nodes('/*:ps/*:p') t(c)
WHERE NOT EXISTS (
        SELECT 1
        FROM dbo.p p
        WHERE p.ID = l.ID
    )