Creating xml Data Type Columns and insert data : XML « XML « SQL Server / T-SQL Tutorial






5>
6>  CREATE TABLE dbo.Book(
7>  BookID int IDENTITY(1,1) PRIMARY KEY,
8>  ISBN char(10) NOT NULL,
9>  BookName varchar(250) NOT NULL,
10>  AuthorID int NOT NULL,
11>  ChapterDESC XML NULL)
12>  GO
1>
2>  CREATE PROCEDURE dbo.usp_INS_Book
3>  @ISBN char(10),
4>  @BookName varchar(250),
5>  @AuthorID int,
6>  @ChapterDESC xml
7>  AS
8>  INSERT dbo.Book
9>  (ISBN, BookName, AuthorID, ChapterDESC)
10>  VALUES (@ISBN, @BookName, @AuthorID, @ChapterDESC)
11>  GO
1>
2> --Inserting xml Data into a Column
3>
4> INSERT dbo.Book
5> (ISBN, BookName, AuthorID, ChapterDESC)
6> VALUES ('1111','SQL Server',55,
7> CAST('<Book name="SQL Server">
8~ <Chapters>
9~ <Chapter id="1"> a </Chapter>
10~  <Chapter id="2"> b </Chapter>
11~  <Chapter id="3"> c </Chapter>
12~  <Chapter id="4"> d </Chapter>
13~  <Chapter id="5"> e </Chapter>
14~  <Chapter id="6"> f </Chapter>
15~  </Chapters>
16~  </Book>' as XML))
17>  GO

(1 rows affected)
1>
2>
3> select * from dbo.book
4> GO
BookID      ISBN       BookName
                                                                          AuthorID    ChapterDESC

----------- ---------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------- ----------- ------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
          1 1111       SQL Server
                                                                                   55 <Book name="SQL Server"><Chapters><Chapter id="1"> a </Chapter><Chapter id="2"> b </Chapter><Chapter id="3"> c </C
hapter><Chapter id="4"> d </Chapter><Chapter id="5"> e </Chapter><Chapter id="6"> f </Chapter></Chapters></Book>

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








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