<tfoot id='3yTR4'></tfoot>

    <small id='3yTR4'></small><noframes id='3yTR4'>

  • <legend id='3yTR4'><style id='3yTR4'><dir id='3yTR4'><q id='3yTR4'></q></dir></style></legend>
  • <i id='3yTR4'><tr id='3yTR4'><dt id='3yTR4'><q id='3yTR4'><span id='3yTR4'><b id='3yTR4'><form id='3yTR4'><ins id='3yTR4'></ins><ul id='3yTR4'></ul><sub id='3yTR4'></sub></form><legend id='3yTR4'></legend><bdo id='3yTR4'><pre id='3yTR4'><center id='3yTR4'></center></pre></bdo></b><th id='3yTR4'></th></span></q></dt></tr></i><div id='3yTR4'><tfoot id='3yTR4'></tfoot><dl id='3yTR4'><fieldset id='3yTR4'></fieldset></dl></div>

          <bdo id='3yTR4'></bdo><ul id='3yTR4'></ul>

        SQL Server 查询 XML 数据类型性能问题

        时间:2023-06-05

            1. <tfoot id='qpfKj'></tfoot>
            2. <small id='qpfKj'></small><noframes id='qpfKj'>

              <legend id='qpfKj'><style id='qpfKj'><dir id='qpfKj'><q id='qpfKj'></q></dir></style></legend>
                <bdo id='qpfKj'></bdo><ul id='qpfKj'></ul>

                <i id='qpfKj'><tr id='qpfKj'><dt id='qpfKj'><q id='qpfKj'><span id='qpfKj'><b id='qpfKj'><form id='qpfKj'><ins id='qpfKj'></ins><ul id='qpfKj'></ul><sub id='qpfKj'></sub></form><legend id='qpfKj'></legend><bdo id='qpfKj'><pre id='qpfKj'><center id='qpfKj'></center></pre></bdo></b><th id='qpfKj'></th></span></q></dt></tr></i><div id='qpfKj'><tfoot id='qpfKj'></tfoot><dl id='qpfKj'><fieldset id='qpfKj'></fieldset></dl></div>
                  <tbody id='qpfKj'></tbody>
                  本文介绍了SQL Server 查询 XML 数据类型性能问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我有一个 XML 文件存储在我的表 recordsXML 数据类型列 data 中.

                  I have a XML file stored in a XML datatype column data in my table records.

                  表格如下所示:

                  create table records 
                  (
                       id int,
                       type nvarchar(28),
                       data xml,
                       posted datetime
                  )
                  

                  XML 数据:

                  <Properties>
                      <data>
                          <Name>novel</Name>
                          <Gender>Female</Gender>
                          <Age>32</Age>
                          <Salary>55k</Salary>
                          <Phone>123-123</Phone>
                      </data>
                  </Properties>
                  

                  我目前正在使用以下查询从该 XML 列中提取数据,这在 20K 条记录中需要花费超过几分钟的时间.

                  I am currently using following query to extract data from that XML column which is taking more than minutes in 20K records.

                  select
                      id,
                      posteddate,
                      CONVERT( NVARCHAR(500), data.query('data(Properties/data/Name)') ) AS Name,
                      CONVERT( NVARCHAR(500), data.query('data(Properties/data/Gender)') ) AS Gender,
                      CONVERT( NVARCHAR(500), data.query('data(Properties/data/Age)') ) AS Age,
                      CONVERT( NVARCHAR(500), data.query('data(Properties/data/Salary)') ) AS Salary,
                      CONVERT( NVARCHAR(500), data.query('data(Properties/data/Phone)') ) AS Phone
                  from 
                      records
                  where 
                      type = 'personnel_xml'
                  

                  任何人都可以帮助解释我如何优化这个场景,因为我需要从存储为列的 XML 中提取 100 个这样的元素.

                  Can anybody help explain how can I optimize this scenario as I need to extract 100 such elements from my XML stored as a column.

                  推荐答案

                  假设您在 XML 中有多个 .请注意,我添加了一个扩展的 XML 文件,该文件将有两组.

                  Assuming you have multiple <data> within the XML. Notice I added an expanded XML file which will have two sets.

                  Declare @table table (id int,data xml)
                  Insert Into @table values (1,'<Properties><data><Name>novel</Name><Gender>Female</Gender><Age>32</Age><Salary>55k</Salary><Phone>123-123</Phone></data>
                  <data><Name>Another Name</Name><Gender>Male</Gender><Age>45</Age><Salary>75k</Salary><Phone>555-1212</Phone></data>
                  </Properties>')
                  
                  ;with cte as (
                        Select ID
                              ,RN   = Row_Number() over (Partition By ID Order By (Select Null))
                              ,Data = m.query('.') 
                        From   @table AS t
                        Cross Apply t.Data.nodes('/Properties/data') AS A(m)
                   )
                  Select ID
                        ,RN
                        ,Name   = Data.value('(data/Name)[1]'  ,'nvarchar(500)')
                        ,Gender = Data.value('(data/Gender)[1]','nvarchar(500)')
                        ,Age    = Data.value('(data/Age)[1]'   ,'nvarchar(500)')
                        ,Salary = Data.value('(data/Salary)[1]','nvarchar(500)')
                        ,Phone  = Data.value('(data/Phone)[1]' ,'nvarchar(500)')
                   From  cte
                  

                  退货

                  ID  RN  Name            Gender  Age     Salary  Phone
                  1   1   novel           Female  32      55k     123-123
                  1   2   Another Name    Male    45      75k     555-1212
                  

                  这篇关于SQL Server 查询 XML 数据类型性能问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:带有 CDATA 块的 SQL Server XML 数据 下一篇:在单个查询中将多个节点插入到 xml 字段

                  相关文章

                  最新文章

                • <small id='olZGc'></small><noframes id='olZGc'>

                  <i id='olZGc'><tr id='olZGc'><dt id='olZGc'><q id='olZGc'><span id='olZGc'><b id='olZGc'><form id='olZGc'><ins id='olZGc'></ins><ul id='olZGc'></ul><sub id='olZGc'></sub></form><legend id='olZGc'></legend><bdo id='olZGc'><pre id='olZGc'><center id='olZGc'></center></pre></bdo></b><th id='olZGc'></th></span></q></dt></tr></i><div id='olZGc'><tfoot id='olZGc'></tfoot><dl id='olZGc'><fieldset id='olZGc'></fieldset></dl></div>

                  1. <legend id='olZGc'><style id='olZGc'><dir id='olZGc'><q id='olZGc'></q></dir></style></legend>
                    1. <tfoot id='olZGc'></tfoot>
                        <bdo id='olZGc'></bdo><ul id='olZGc'></ul>