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.
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