How to Use BCP to Import an XML File
- 1). Open SQL Server Management Studio and then open the database to work with.
- 2). Open a Query window.
- 3). Type the following query in which your XML file, with a TXT file extension, replaces the file and path. Your table name replaces the “Z” in the statement. Click the Run button to execute the query.
INSERT INTO Z(XmlCol)
SELECT * FROM OPENROWSET(
BULK 'c:\DataFolder\XMLDataFile.txt',
SINGLE_BLOB) AS x
The XML data file is imported as a single cell into Table Z. - 1). Open a Query window in SQL Server Management Studio.
- 2). Type the following query to display the initial state of the XML column values before updating the cells:
SELECT * FROM Z
UPDATE Z
SET XmlCol =(
SELECT * FROM OPENROWSET(
BULK 'C:\DataFolder\XMLDataFile.txt',
SINGLE_BLOB
) AS x
)
WHERE IntCol = 1
GO - 3). Click the Run button on the top navigation bar in the Query window. The XML file is imported, and the SQL table is updated.
Import XML as Binary Data
Import XML Into Existing Row
Source...