The Best Way to shred XML data into SQL Server database columns

Posted by eddiegroves on Stack Overflow See other posts from Stack Overflow or by eddiegroves
Published on 2008-09-14T09:39:29Z Indexed on 2010/06/03 8:04 UTC
Read the original article Hit count: 229

Filed under:
|

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:

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)

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

© Stack Overflow or respective owner

Related posts about sql-server

Related posts about Xml