I am trying to create a small console application in C # to perform insertions in the product table (ITEMS) in SQL Server 2008 according to the contents of the XML file in FASTEST mode. I already have an .XSD file that contains the correct mappings to the SQL table (which may not be necessary using the approach described below).
Here's a high level of my approach:
- Read the XML using it to create the table.
- Execute MERGE in the ITEMS table using the table created from the XML file.
2a. If the item exists, update it.
2b. If the item does not exist, insert it. - Create a log of only records inserted in XML.
Consider the following ITEMS table and XML file:
POSITIONS
Item_Id Name Price
1 Coke 5.00
2 Pepsi 3.00
3 Sprite 2.00
ITEMS.XML
<?xml version="1.0" encoding="ISO-8859-1"?>
<Item>
<Id>5</Id>
<Name>Mountain Dew</Name>
<Price>4.50</Price>
</Item>
<Item>
<Id>3</Id>
<Name>Sprite Zero</Name>
<Price>1.75</Price>
</Item>
After import, the ITEMS table should look like this:
POSITIONS
Item_Id Name Price
1 Coke 5.00
2 Pepsi 3.00
3 Sprite Zero 1.75
5 Mountain Dew 4.50
XML, , (ITEMS_LOG.XML):
ITEMS_LOG.XML
<?xml version="1.0" encoding="ISO-8859-1"?>
<Item>
<Id>5</Id>
<Name>Mountain Dew</Name>
<Price>4.50</Price>
</Item>
SQLXMLBulkLoad, , , , SQL Server ( , /). SQL, XML, . / !