SQLServer2005 XML Data Manipulation code _mssql2005

Source: Internet
Author: User
Example:
CREATE table
Copy Code code as follows:

CREATE TABLE [dbo]. [XmlTable] (
[ID] [int] IDENTITY (1,1) not NULL,
[Doc] [XML] NULL
)


One. Inserting data
1. Insert via XML file
1.xml
Copy Code code as follows:

<?xml version= ' 1.0 ' encoding= ' utf-8 '?>
<dd>
<a id= "2" >dafaf2</a>
<a id= "3" >dafaf3</a>
<a id= "4" >dafaf4</a>
</dd>

Copy Code code as follows:

Insert into xmlTable (DOC)
SELECT * FROM
OpenRowset (BULK ' C:\Documents and settings\administrator\ desktop \1.xml ', Single_clob) as X

2. Inserting by string
Insert into xmlTable (DOC) VALUES (' <dd><a>123</a></d> ')

Two. Inquire
Select Doc.value (' (/dd/a[@id >2]) [1] ', ' nvarchar ') as XM from xmlTable
SELECT * from xmlTable where Doc.value (' (/dd/a[@id >2]) [1] ', ' nvarchar (50) ') = ' Blog Park '
Three. Update
1. Insert Node
Update xmlTable set doc.modify (' Insert <a>123</a> into (/DD) [1] ')
Note: Insert < node to insert > INSERT INTO < node >
Into--insert inside
After--insert the node behind
Before--insert front of node
2. Delete node
Update xmlTable
Set Doc.modify (' Delete (/dd/a) [1] ')--Deletes the first node of the/dd/a
3. Modify the Node
Update xmlTable
Set doc.modify (' Replace value of (/dd/a/text ()) [1] with "blog Garden")


Just learn so much for the time being and write later ...

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.