SQLServer2005 XML数据操作代码
时间:2024-01-27 11:50:17
示例:
创建Table
CREATE TABLE [dbo].[xmlTable](
[id] [int] IDENTITY(1,1) NOT NULL,
[doc] [xml] NULL
)
一。插入数据
1.通过XML文件插入
1.xml
<?xml version='1.0' encoding='utf-8' ?>
<dd>
<a id="2">dafaf2</a>
<a id="3">dafaf3</a>
<a id="4">dafaf4</a>
</dd>
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('<dd><a>123</a></d>')
二。查询
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 <a>123</a> 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 "博客园"')
暂时只学到这么多,以后再写。。。
标签:XML,数据操作
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
保存透明gif时出现锯齿解决法
2008-06-26 18:10:00
![](https://img.aspxhome.com/file/UploadPic/20086/26/2008626181821662s.gif)
Python线性表种的单链表详解
2022-03-02 07:36:58
![](https://img.aspxhome.com/file/2023/4/90694_0s.png)
Python3 实现文件批量重命名示例代码
2023-06-18 00:08:32
![](https://img.aspxhome.com/file/2023/7/72127_0s.jpg)
Python paramiko 模块浅谈与SSH主要功能模拟解析
2023-10-01 11:06:28
![](https://img.aspxhome.com/file/2023/7/66007_0s.png)
Python网络编程中urllib2模块的用法总结
2022-05-26 18:49:53
![](https://img.aspxhome.com/file/2023/7/107637_0s.png)
Mysql中正则表达式Regexp常见用法及说明
2024-01-14 21:51:35
zabbix 监控mysql的方法
2024-01-16 02:11:04
![](https://img.aspxhome.com/file/2023/1/93891_0s.png)
Python cookbook(数据结构与算法)筛选及提取序列中元素的方法
2023-04-27 19:46:34
Python select及selectors模块概念用法详解
2022-11-30 20:06:24
MySQL命令行导出与导入数据库
2024-01-14 03:30:14
Git原理和常用操作
2023-02-01 23:55:55
![](https://img.aspxhome.com/file/2023/7/123737_0s.png)
JavaScript变量提升和严格模式实例分析
2024-04-17 10:35:52
如何在Python中将字符串转换为集合
2023-08-26 07:31:11
![](https://img.aspxhome.com/file/2023/0/62850_0s.png)
python内置函数sorted()用法深入分析
2022-06-26 07:41:40
python 实现体质指数BMI计算
2023-01-25 12:44:56
![](https://img.aspxhome.com/file/2023/1/110571_0s.png)
解决django中form表单设置action后无法回到原页面的问题
2023-06-27 00:27:54
php通过exif_read_data函数获取图片的exif信息
2023-10-27 09:01:44
centos 7安装mysql5.5的方法
2024-01-22 01:29:32
![](https://img.aspxhome.com/file/2023/1/112691_0s.jpg)
通俗易懂详解Python基础五种下划线作用
2024-01-01 06:36:22
![](https://img.aspxhome.com/file/2023/5/70645_0s.png)
10分钟搞定让你困惑的 Jenkins 环境变量过程详解
2023-09-23 13:56:03
![](https://img.aspxhome.com/file/2023/9/131839_0s.png)