<p>What is the best way to shred XML data into various database columns? So far I have mainly been using the nodes and value functions like so:</p>

<pre><code>INSERT INTO some_table (column1, column2, column3)
SELECT
Rows.n.value('(@column1)[1]', 'varchar(20)'),
Rows.n.value('(@column2)[1]', 'nvarchar(100)'),
Rows.n.value('(@column3)[1]', 'int'),
FROM @xml.nodes('//Rows') Rows(n)
</code></pre>

<p>However I find that this is getting very slow for even moderate size xml data.</p>

I'm not sure what is the best method. I used OPENXML construction:
```
```
INSERT INTO Test
SELECT Id, Data 
FROM OPENXML (@XmlDocument, '/Root/blah',2)
WITH (Id   int         '@ID',
      Data varchar(10) '@DATA')
```
```
To speed it up, you can create XML indices. You can set index specifically for
value
function performance optimization. Also you can use typed xml columns, which performs better.