Insert XML data into SQL Server Database Table

Title

Insert XML data into SQL Server Database Table

Introduction

If you are creating a new table then the column in which you want to store XML file, provide column type as XML and in case you have existing database, then change column type to XML using ALTER TABLE statement.

In this example I’ve created a Test table with following structure.




 

How to insert XML data into SQL Server Database Table?

 

 

 

 

 

 

 

 

 

Use command sp_help ‘dbo.Test’ to check structure of table.

Now I’ll be inserting a fresh row into the database, in order to add XML data in database use INSERT INTO Statement, see example below.

 

insert into dbo.Test VALUES('Demo Data',' <note>

<to>To</to>

<from>John</from>

<heading>Reminder</heading>

<body>Doctor`s Appointment at 5</body>

</note>');

Here is my XML file




<note>

<to>To</to>

<from>John</from>

<heading>Reminder</heading>

<body>Doctor`s Appointment at 5</body>

</note>

 

I used INSERT statement to insert data in to the database table

How to insert XML data into SQL Server Database Table?


JavaScript, ASP.Net & PHP Web Developer. Connect with me on Facebook and Twitter.

Share This Post

Related Articles

Powered by Paras Babbar · Designed by Paras Babbar