Posts Tagged ‘Import XML data into sql server table’
Hello friends some guys asking me about is this any way to imports XML data into sql server table.
so friends here is answer of your question please follow the step and you will fill happy after task will done.
Step 1: Create one table in the
CREATE TABLE Customer (ID int NOT NULL, Name xml)
Step 2: Then After create a XML file .
<?xml version=”1.0″ encoding=”UTF-8″?>
<Customers>
<Customer ID=”1″>
<Name>Test</Name>
</Customer>
</Customers>
<Customers>
<Customer ID=”2″>
<Name>Data</Name>
</Customer>
</Customers>
Save this XML file name as test.xml into C:\ drive of your computer.
Step 3: Now import the xml data from C:\test.xml into newly created table ‘Customer’
INSERT INTO Customer(ID, Name)
SELECT 1, Name
FROM
(
SELECT * FROM OPENROWSET(BULK ‘c:\test.xml’,SINGLE_BLOB) as Disc
) AS ImportXML (Disc)
Note: Do not forget to specify the UTF-8 encoding scheme in the XML file.
Enjoy Friends.
Hello ! I am Arjun Jadeja a Software Engineer by Profession. You can contribute and I will distribute your ideas through this site. Thanks and Enjoy