How To Import XML Into SQL Server With The XML Bulk Load Component
How To Import XML Into SQL Server With The XML Bulk Load Component
Article ID: 316005 - Last Review: December 23, 2005 - Revision: 4.4
How to import XML into SQL Server with the XML Bulk Load component
This article was previously published under Q316005
SUMMARY
Data that is expressed in XML can be loaded into a Microsoft SQL Server 2000
database by using the XML Bulk Load component. This article outlines the steps that you need to follow to load XML data
into a table that already exists in the database.
Note If you are using Microsoft SQL Server 2005, see the "XML Bulk Load Examples" topic in SQL Server 2005 Books
Online.
Requirements
To use the steps in this article you need:
Knowledge of XML.
USE MyDatabase CREATE TABLE Customer ( CustomerId INT PRIMARY KEY, CompanyName NVARCHAR(20), City
NVARCHAR(20))
C orrect the ConnectionString credentials on the second line of the code so that the script can work with your SQL
Server installation. If you do not correct line 2, the following error message occurs after you execute the script: Error
connecting to the data source
Verify it works
In SQL Query Analyzer, switch to the MyDatabase database, and then run this query:
Note that the three records created in the "C reate the XML data source file" heading are now in the Customer table.
Alternate technique
The XML Bulk Load component is capable of:
Mapping an XML document to multiples tables by using a relationship specified in the XML schema file.
Generating table schemas before bulk loading.
Bulk loading from a stream.
Bulk loading in overflow columns.
REFERENCES
SQLXML Books Online; topic: "Performing Bulk Load of XML Data"
APPLIES TO
http://support.microsoft.com/kb/316005 2/3
22-06-2010 How to import XML into SQL Server wit…
Microsoft SQL Server 2005 Express Edition
Microsoft SQL Server 2005 Workgroup Edition
Microsoft Support
©2010 Microsoft
http://support.microsoft.com/kb/316005 3/3