Home > Database > Mysql Tutorial > SQLServer2005 XML数据操作代码

SQLServer2005 XML数据操作代码

WBOY
Release: 2016-06-07 18:05:07
Original
940 people have browsed it

在项目中经常用XML文件,看看T-SQL程序设计发现SQLSERVER2005居然可以处理XML类型,而且还可以使用类似于Xpath的查询语法查询。

示例:
创建Table
代码如下:
CREATE TABLE [dbo].[xmlTable](
[id] [int] IDENTITY(1,1) NOT NULL,
[doc] [xml] NULL
)


一。插入数据
1.通过XML文件插入
1.xml
代码如下:


dafaf2
dafaf3
dafaf4


代码如下:
insert into xmlTable(doc)
select * from
openrowset(BULK 'C:\Documents and Settings\Administrator\桌面\1.xml',SINGLE_CLOB) as x

2.通过字符串插入
insert into xmlTable(doc) values('
123')

二。查询
select doc.value('(/dd/a[@id>2])[1]','nvarchar(50)') as xm from xmlTable
select * from xmlTable where doc.value('(/dd/a[@id>2])[1]','nvarchar(50)') ='博客园'
三。更新
1.插入节点
update xmlTable set doc.modify('insert 123 into (/dd)[1]')
注:insert 插入到
into --插入里面
after --插入节点后面
before --插入节点前面
2.删除节点
update xmlTable
set doc.modify('delete (/dd/a)[1]') --删除 /dd/a 的第一个节点
3.修改节点
update xmlTable
set doc.modify('replace value of (/dd/a/text())[1] with "博客园"')


暂时只学到这么多,以后再写。。。
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template