0
我正在嘗試完成家庭作業分配以創建,插入,修改和查詢XML表。到目前爲止,我已經能夠創建表格並插入一些數據行;但是,我卡在修改後的部分。我創建了查詢併成功執行,但未插入新的材料節點。我必須在所有功能節點下插入此子節點。SQL Server 2014查詢更新插入XML節點成功但未插入節點
CREATE TABLE Prod_Catalog
(
ID int NOT NULL Primary Key,
xCol xml NOT NULL,
)
-
INSERT INTO dbo.Prod_Catalog VALUES
(1,'<root><productdescription ProductID="P5500xs" ProductName="Brava 55 TV">
<features>Features
<warranty>5 years</warranty>
<maintenance>Dont hit with hammer</maintenance>
</features></productdescription>
</root>'),
(2,'<root><productdescription ProductID="G29-2" ProductName="Panasonic 1100Watt Microwave">
<features>Features
<warranty>1 year</warranty>
<maintenance>Dont cook metal forks!</maintenance>
</features></productdescription>
</root>'),
(3,'<root><productdescription ProductID="LG22-XL" ProductName="LG 20 cubic refrigerator">
<features>Features
<warranty>1 year</warranty>
<maintenance>Makes things cold.</maintenance>
</features></productdescription>
</root>')
-
UPDATE dbo.Prod_Catalog
SET xCol.modify('insert <materials>Electronics,Glass,Flashy Lights</materials> as first into (/root/productiondescription[@ProductID=("P5500xs")]/features)[1]');
GO
-
(3 row(s) affected)
-
<root><productdescription ProductID="P5500xs" ProductName="Brava 55 TV"><features>Features<warranty>5 years</warranty><maintenance>Dont hit with hammer</maintenance></features></productdescription></root>
<root><productdescription ProductID="G29-2" ProductName="Panasonic 1100Watt Microwave"><features>Features<warranty>1 year</warranty><maintenance>Dont cook metal forks!</maintenance></features></productdescription></root>
<root><productdescription ProductID="LG22-XL" ProductName="LG 20 cubic refrigerator"><features>Features<warranty>1 year</warranty><maintenance>Makes things cold.</maintenance></features></productdescription></root>
-
任何建議或方向得到這個真正工作大加讚賞。
謝謝!
'productiondescription'不是元素名稱。 'productdescription'是。 – 2015-02-11 07:27:30