OPENXML is a SQL Server table-valued function for shredding XML into relational rows and columns. It suits hierarchical employee, contract, and skill data, but requires parsed XML and careful cleanup. section 3.4.1
Mistake 1: treating OPENXML as a complete XML parser. A safer workflow is:
- Store or receive the XML document. section 3.4.1
- Call sp_xml_preparedocument to create an in-memory parsed representation and handle. section 3.4.1
- Pass the handle, an XPath row pattern, and mappings to OPENXML; use ../ to reach parent levels. section 3.4.1
- Call sp_xml_removedocument immediately afterward to release consumed memory. section 3.4.1
Employee contracts and skills
An EmployeeContracts document can contain employees, repeated contracts, and repeated skills. OPENXML can flatten this hierarchy into employee, contract, and skill columns for relational storage.
