Shredding XML Using OPENXML
Up to this point, you have been using FOR XML to compose XML from rows of data, but what if you already have XML data and want to shred it back into relational data? SQL Server 2000 introduced a feature called OPENXML for this purpose. The OPENXML system function is designed for this purpose, and allows an XML document file to be shredded into T-SQL rows as we’ll explain next. Since the introduction of the native xml data type in SQL Server 2005, XQuery (covered in the next section) offers even more choices for extracting data from XML input.
To shred data XML into relational rows using OPENXML, you first create a handle to the XML document using the system stored procedure sp_xml_preparedocument. This system-stored ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access