示例: 创建Table <div class="codetitle"><a style="CURSOR: pointer" data="89500" class="copybut" id="copybut89500" onclick="doCopy('code89500')"> 代码如下:<div class="codebody" id="code89500"> CREATE TABLE [dbo].[xmlTable]( [id] [int] IDENTITY(1,1) NOT NULL, [doc] [xml] NULL ) 一。插入数据 1.通过XML文件插入 1.xml <div class="codetitle"><a style="CURSOR: pointer" data="81214" class="copybut" id="copybut81214" onclick="doCopy('code81214')"> 代码如下:<div class="codebody" id="code81214"> <?xml version='1.0' encoding='utf-8' ?> <a id="2">dafaf2 <a id="3">dafaf3 <a id="4">dafaf4 <div class="codetitle"><a style="CURSOR: pointer" data="59187" class="copybut" id="copybut59187" onclick="doCopy('code59187')"> 代码如下:<div class="codebody" id="code59187"> insert into xmlTable(doc) select from openrowset(BULK 'C:Documents and SettingsAdministrator桌面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 "博客园"') 暂时只学到这么多,以后再写。。。 (编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|