如何对SQL Server中的XML数据进行insert,update,delete
1个回答
2017-06-19
展开全部
A.利用as first,at last,before,after四个参数将元素插入指定的位置
set @XMLVar.modify(
'insert <first name="at first" /> as first into (/catalog[1]/book[1])')
set @XMLVar.modify(
'insert <last name="at last"/> as last into (/catalog[1]/book[1])')
set @XMLVar.modify(
'insert <before name="before"/> before (/catalog[1]/book[1]/author[1])')
set @XMLVar.modify(
'insert <after name="after"/> after (/catalog[1]/book[1]/author[1])')
SELECT @XMLVar.query('/catalog[1]/book[1]');
结果集为:
1: <book category="ITPro">
2: <first name="at first" />
3: <title>Windows Step By Step</title>
4: <before name="before" />
5: <author>Bill Zack</author>
6: <after name="after" />
7: <price>49.99</price>
8: <last name="at last" />
9: </book>
set @XMLVar.modify(
'insert <first name="at first" /> as first into (/catalog[1]/book[1])')
set @XMLVar.modify(
'insert <last name="at last"/> as last into (/catalog[1]/book[1])')
set @XMLVar.modify(
'insert <before name="before"/> before (/catalog[1]/book[1]/author[1])')
set @XMLVar.modify(
'insert <after name="after"/> after (/catalog[1]/book[1]/author[1])')
SELECT @XMLVar.query('/catalog[1]/book[1]');
结果集为:
1: <book category="ITPro">
2: <first name="at first" />
3: <title>Windows Step By Step</title>
4: <before name="before" />
5: <author>Bill Zack</author>
6: <after name="after" />
7: <price>49.99</price>
8: <last name="at last" />
9: </book>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询