Insert xml data into SQL Server

Posted In database - By admin On Tuesday, August 4th, 2009 With 1 Comment

XML is one of the data types in SQL Server 2005 and 2008.It is considered as one of the significant changes introduced in SQL Server 2005.In the previous versions, storing and retrieving XML data were possible but it was not as easy and extensible as it is in the current version. The XML data type lets the user to store XML data in the SQL Server database. In this article we will be discussing how to store, retrieve and query XML data.

Let’s now take a look at an example. This example demonstrates how to create a table that contains an XML column. We will also insert some records into the table.

1. Create table with XML column

Create table Product(ProductID int,ProductName varchar(50),ProductDetails XML)

2. Insert valid XML data into the table:

Insert into Product values(1,’Parker‘,’<ROOT><Product>501,Pen, Parker,$500</Product></ROOT>‘)

3. We can also create variables of XML type.

Declare @x xml
SET @x =’<ROOT><Product>501,Pen, Parker,$500</Product></ROOT>
Insert into Product values(1,’Parker‘,@x)

Tags:

About -

Displaying 1 Comments
Have Your Say

  1. pinkz says:

    What are the words … super, wonderful phrase

    [Reply]

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>