Sudantha
Sudantha

Reputation: 16214

Push XML data directly to SQL Server

ELEMENTS` will return SQL data directly as XML , is there is a proper way of pushing a XML file directly to SQL server ?

Upvotes: 0

Views: 195

Answers (1)

Bogdan Sahlean
Bogdan Sahlean

Reputation: 1

If you need to import xml files into a database then I would use BULK INSERT or OPENROWSET(BULK 'filename', SINGLE_BLOB) (ref:BOL):

DECLARE @BulkImport TABLE (
    ID INT IDENTITY,
    X XML
);

INSERT  @BulkImport (X)
SELECT  a.b
FROM    OPENROWSET(BULK N'd:\src.xml', SINGLE_BLOB) AS a(b);

SELECT  *
FROM    @BulkImport;

Results:

ID          X
----------- -----------------------------
1           <row PurchaseOrderID="10" ...

Upvotes: 2

Related Questions