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