现在的位置: 首页 > 综合 > 正文

SQL Server 更新xml列

2013年08月26日 ⁄ 综合 ⁄ 共 382字 ⁄ 字号 评论关闭
declare @xmlContent xml
set @xmlContent = '<book name="SQL Server 2005">
	<author>张三</author>
	<author></author>
</book>'

--更新属性
set @xmlContent.modify('
replace value of (/book/@name)[1]
with "SQL Server 2008"')
--更新一个有内容节点的内容
set @xmlContent.modify('
replace value of (/book/author[1]/text())[1]
with "李四"')
--更新一个无内容节点的内容,这里使用insert
set @xmlContent.modify('
insert text{"王五"}
into (/book/author[2])[1]')
select @xmlContent

抱歉!评论已关闭.