Modify XML data in SQL

Source: Internet
Author: User

 

 

 

Today, the data on the cloud went wrong. As a result, the original script bat was renamed cmd. Only data can be modified.

Original data:

<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>

 

Modify command:

update dbo.MachineConfigs set CreatorConfig.modify('replace value of 
(/VStormCliCreator/PostScripts/PostScript/text())[1] with ("\\172.23.93.230\scratch$\v-XXX\Run.cmd")') 
where ID = '49E6303D-577D-43C8-BB57-0533FC19BBEC' select * from dbo.MachineConfigs  where ID = '49E6303D-577D-43C8-BB57-0533FC19BBEC'

 

The following data:

<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>
 
I would like to thank Guo Yongcheng for his http://blog.csdn.net/tjvictor/archive/2009/07/21/4368496.aspx on how to insert update Delete XML data in SQL Server.

Modify Method

This method can update XML data. The insert, delete, and update keywords added in XQuery provide support for xml dml. You can use the insert, delete, and update keywords to insert, delete, and update one or more nodes respectively. For example, enter the following code in the query window:

 UPDATE books SET xmlCol.modify(  'insert  <section num="1">  <content>Background</content> </section> after (/book/title)[1]')  where id = 1

Use the update statement to modify the xmlcol field in the books table in row 1st of the Code section ~ Use Insert in 7 rows

Code
   1 <book type="computer" publicationdate="2008" ISBN="0-7356-1588-2">   
2 <title>c#</title>
3  <author>
4 <first-name>sheng</first-name>
5 <last-name>bin</last-name>
6 </author>
7 <author>
8 <first-name>gengxin</first-name>
9 <last-name>sun</last-name>
10 </author>
11 <price>35.99</price>
12 </book>

 

After executing this code segment, add the element section to the xmlcol column of the record with the ID column value of 1. This element will be added to the title element. The content of the modified xmlcol column is as follows.

Code
    1 <book type="computer" publicationdate="2008" ISBN="0-7356-1588-2">    
2 <title>c#</title>
3 <section num="1">
4 <content>Background</content>
5 </section>
6 <author>
7 <first-name>sheng</first-name>
8 <last-name>bin</last-name>
9 </author>
10 <author>
11 <first-name>gengxin</first-name>
12 <last-name>sun</last-name>
13 </author>
14 <price>35.99</price>
15 </book>

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.