您的位置:首页 > 数据库

SQL 中对XML数据的修改

2010-07-16 16:56 411 查看
今天云次那个数据出错,一看,靠,原来的脚本Bat改称cmd了。只能修改数据了。

原来的数据:

<VStormCliCreator>
<MachineName>B1-Site</MachineName>
<NIC>TrunkNetworkSwitch</NIC>
<Host>MSD-1531346.fareast.corp.microsoft.com</Host>
<Memory>4096</Memory>
<Password>User@123</Password>
<VLanID>979</VLanID>
<PostScripts>
<PostScript>\\172.23.93.230\scratch$\v-XXX\Run.bat</PostScript>
</PostScripts>
<ImageName>97-SP2</ImageName>
<OSID>97</OSID>
</VStormCliCreator>


修改命令:

updatedbo.MachineConfigssetCreatorConfig.modify('replacevalueof

(/VStormCliCreator/PostScripts/PostScript/text())[1]with("\\172.23.93.230\scratch$\v-XXX\Run.cmd")')

whereID='49E6303D-577D-43C8-BB57-0533FC19BBEC'

select*fromdbo.MachineConfigswhereID='49E6303D-577D-43C8-BB57-0533FC19BBEC'


该后的数据:

<VStormCliCreator>
<MachineName>B1-Site</MachineName>
<NIC>TrunkNetworkSwitch</NIC>
<Host>MSD-1531346.fareast.corp.microsoft.com</Host>
<Memory>4096</Memory>
<Password>User@123</Password>
<VLanID>979</VLanID>
<PostScripts>
<PostScript>\\172.23.93.230\scratch$\v-XXX\Run.cmd</PostScript>
</PostScripts>
<ImageName>97-SP2</ImageName>
<OSID>97</OSID>
</VStormCliCreator>


着重感谢郭勇成的《如何对SQLServer中的XML数据进行insertUpdatedelete》http://blog.csdn.net/tjvictor/archive/2009/07/21/4368496.aspx


 补充点详细资料:

modify方法

该方法可以对XML数据进行更新。通过XQuery中添加的insert、delete和update关键字提供了对XMLDML的支持,使用insert、delete和update关键字可以分别插入、删除和更新一个或多个节点。例如,在查询窗口中输入以下代码:

UPDATEbooksSETxmlCol.modify('insert<sectionnum="1"><content>Background</content></section>after(/book/title)[1]')whereid=1


在该段代码的第1行使用UPDATE语句修改books表中xmlCol类型的字段,在第2~7行使用insert

代码[code]<booktype="computer"publicationdate="2008"ISBN="0-7356-1588-2">
<title>c#</title>
<sectionnum="1">
<content>Background</content>
</section>
<author>
<first-name>sheng</first-name>
<last-name>bin</last-name>
</author>
<author>
<first-name>gengxin</first-name>
<last-name>sun</last-name>
</author>
<price>35.99</price>
</book>


[/code]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐