Modifying XML Data : XML « XML « SQL Server / T-SQL Tutorial

Home
SQL Server / T-SQL Tutorial
1.Query
2.Insert Delete Update
3.Table
4.Table Join
5.Data Types
6.Set Operations
7.Constraints
8.Subquery
9.Aggregate Functions
10.Date Functions
11.Math Functions
12.String Functions
13.Data Convert Functions
14.Analytical Functions
15.Sequence Indentity
16.View
17.Index
18.Cursor
19.Database
20.Transact SQL
21.Procedure Function
22.Trigger
23.Transaction
24.XML
25.System Functions
26.System Settings
27.System Tables Views
28.User Role
29.CLR
SQL Server / T-SQL Tutorial » XML » XML 
24.1.7.Modifying XML Data
3>
4CREATE TABLE dbo.ProductBilling
5(ProductBillingID int IDENTITY(1,1PRIMARY KEY,
6> ProductBillingXML XML NOT NULL)
7> GO
1>
2INSERT dbo.ProductBilling(ProductBillingXML)
3> VALUES ('<ProductBilling Billingnumber="1" customerid="22" orderdate="7/1/2005">
4~ <OrderItems>
5~ <Item id="22" qty="1" name="SQL"/>
6~ <Item id="24" qty="1" name="T-SQL"/>
7~ </OrderItems>
8~ </ProductBilling>')
9> GO

(rows affected)
1>
2INSERT dbo.ProductBilling
3(ProductBillingXML)
4> VALUES ('<ProductBilling Billingnumber="1" customerid="40" orderdate="7/11/2005">
5~ <OrderItems>
6~ <Item id="11" qty="1" name="Notes"/>
7~ </OrderItems>
8~ </ProductBilling>')
9> GO

(rows affected)
1>
2INSERT dbo.ProductBilling
3(ProductBillingXML)
4> VALUES ('<ProductBilling Billingnumber="1" customerid="9" orderdate="7/22/2005">
5~ <OrderItems>
6~ <Item id="11" qty="1" name="SQL Notes"/>
7~ <Item id="24" qty="1" name="T-SQL Notes"/>
8~ </OrderItems>
9~ </ProductBilling>')
10> GO

(rows affected)
1>
2> set quoted_identifier off
3>
4UPDATE dbo.ProductBilling
5> SET ProductBillingXML.modify
6('insert <Item id="920" qty="1" name="SQL Server 2005 T-SQL Recipes"/>into (/ProductBilling/OrderItems)[1]')
7WHERE ProductBillingID = 2
8>
9> set quoted_identifier on
10>
11> drop table dbo.ProductBilling
12> GO

(rows affected)
24.1.XML
24.1.1.XML type column
24.1.2.Insert XML data to database
24.1.3.Insert XML data to a XML type column
24.1.4.Creating xml Data Type Columns and insert data
24.1.5.Create index on XML column
24.1.6.Load XML data from a file to table
24.1.7.Modifying XML Data
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.