Declare XML type variable and use it in insert statement : XML column « XML « SQL Server / T-SQL

SQL Server / T-SQL
1. Aggregate Functions
2. Analytical Functions
3. Constraints
4. Cursor
5. Data Set
6. Data Type
7. Database
8. Date Timezone
9. Index
10. Insert Delete Update
11. Math Functions
12. Select Query
13. Sequence
14. Store Procedure Function
15. String Functions
16. Subquery
17. System
18. Table
19. Table Joins
20. Transact SQL
21. Transaction
22. Trigger
23. View
24. XML
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
SQL Server / T-SQL » XML » XML column 
Declare XML type variable and use it in insert statement



3>
4>
5CREATE TABLE dbo.Book(
6> BookID int IDENTITY(1,1PRIMARY KEY,
7> ISBN char(10NOT NULL,
8> BookName varchar(250NOT NULL,
9> AuthorID int NOT NULL,
10> ChapterDESC XML NULL)
11> GO
1CREATE PROCEDURE dbo.usp_INS_Book
2> @ISBN char(10),
3> @BookName varchar(250),
4> @AuthorID int,
5> @ChapterDESC xml
6> AS
7INSERT dbo.Book
8(ISBN, BookName, AuthorID, ChapterDESC)
9> VALUES (@ISBN, @BookName, @AuthorID, @ChapterDESC)
10> GO
1> DECLARE @Book XML
2> SET @Book =
3> CAST('<Book name="SQL Server">
4~ <Chapters>
5~ <Chapter id="1"> chapter </Chapter>
6~ <Chapter id="2"> chapter </Chapter>
7~ <Chapter id="3"> chapter </Chapter>
8~ <Chapter id="4"> chapter </Chapter>
9~ </Chapters>
10~ </Book>' as XML)
11>
12INSERT dbo.Book
13(ISBN, BookName, AuthorID, ChapterDESC)
14> VALUES ('1111111','SQL Server',55,@Book)
15> GO

(rows affected)
1select from dbo.book
2> GO
BookID      ISBN       BookName

                                  AuthorID    ChapterDESC


----------- ---------- -------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
--------------------------------- ----------- --------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------
          1 1111111    SQL Server

                                           55 <Book name="SQL Server"><Chapters><Chapter id="1"> chapter </Chapter><Ch
apter id="2"> chapter </Chapter><Chapter id="3"> chapter </Chapter><Chapter id="4"> chapter </Chapter></Chapters><
/Book>

(rows affected)
1>
2> drop table dbo.book
3> GO

 
Related examples in the same category
1. XML type column
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.