更新存储在 SQL Server 中的 XML 列中的 XML [英] Update XML stored in a XML column in SQL Server

查看:30
本文介绍了更新存储在 SQL Server 中的 XML 列中的 XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 SQL Server 2012 中有一个示例表.我正在运行一些查询,但 .modify() XQuery 方法正在执行但没有更新.

I have a sample table in SQL Server 2012. I am running some queries against but the .modify() XQuery method is executing but not updating.

这是表

为此只是尝试将设置更新为NewTest"

For this just trying to update settings to 'NewTest'

这将执行但没有任何更新!感谢您的帮助!

This will execute but nothing is updating! Thanks for any help!

推荐答案

既然有一个 XML 命名空间 (xmlns:dev="http://www.w3.org/2001/XMLSchema") 在您的 XML 文档中,您必须将其包含在您的 UPDATE 语句中!

Since there is a XML namespace (xmlns:dev="http://www.w3.org/2001/XMLSchema") in your XML document, you must inlcude that in your UPDATE statement!

试试这个:

;WITH XMLNAMESPACES(DEFAULT 'http://www.w3.org/2001/XMLSchema')
UPDATE XmlTable
SET XmlDocument.modify('replace value of (/Doc/@Settings)[1] with "NewTest"')
WHERE XmlId = 1

这篇关于更新存储在 SQL Server 中的 XML 列中的 XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆