我有如下所示的XML,它们表示SQL表数据:
<Project>
<DataSource version="4" type="LiveDatabaseSource">
<ServerName>(local)</ServerName>
</DataSource>
<Tables>
<value>
<TableType>Generated</TableType>
<PopulationDetails version="2" type="PopulationDetails">
<PopulationType>RowCount</PopulationType>
<RowCount>10000</RowCount>
<ProportionTableExists>False</ProportionTableExists>
<Proportion>0</Proportion>
<TimeToPopulate>0</TimeToPopulate>
</PopulationDetails>
<Name>Table1</Name>
<Schema>dbo</Schema>
</value>
<value>
<TableType>Generated</TableType>
<PopulationDetails version="2" type="PopulationDetails">
<PopulationType>RowCount</PopulationType>
<RowCount>10000</RowCount>
<ProportionTableExists>False</ProportionTableExists>
<Proportion>0</Proportion>
<TimeToPopulate>0</TimeToPopulate>
</PopulationDetails>
<InvalidRowBehaviour>SkipRow</InvalidRowBehaviour>
<Included>False</Included>
<Append>False</Append>
<Name>Table2</Name>
<Schema>dbo</Schema>
</value>
</Tables>
</Project>
这位于SQL Server的单个XML列中,还有更多<value>
条目代表数据库中的表。我需要通过搜索PopulationDetails.RowCount
中的值来更新Name
:即,我想使用T-SQL将Table2
更新为60,000的行数。
我可以通过Name
找到正确的节点,但是在更新其对等PopulationDetails.Name
节点中的值时遇到了麻烦。到目前为止,我所拥有的只是更新第n条记录的能力:
UPDATE dbo.SQLGenXML
SET GenXML.modify('replace value of
(/Project/Tables/value/PopulationDetails/RowCount/text()) [1] with ("60000")')
WHERE id = 1;
有很多示例可以根据属性查找节点并更新值,但是这种类型的对等级别搜索(或者我的google-foo很烂)