How to Import XML data from XML File using OPENROWSET in SQL Server

To create a test table with an Identity column, and a column of XML data type use the following code:

CREATE TABLE XML_Test_Table
(
Id INT IDENTITY PRIMARY KEY,
XMLData XML
)

We will read the XML data from the file using the OPENROWSET function and insert it into the XMLData column (you need to specify the path and the xml file name):

INSERT INTO XML_Test_Table(XMLData)
SELECT * FROM OPENROWSET(BULK 'E:\temp\PersonData.xml', SINGLE_BLOB) AS x;

As you can see, XML data is inserted into the XMLData column:

SELECT * FROM XML_Test_Table

import_xml_openrowset

Clicking on the hyperlink open a tab in SSMS with the XML data:

import_xml_openrowset_data