modify() Method
in-place XML modification
What changes
- Input
- xml column or variable and an XML DML expression
- Output or change
- the same xml column (UPDATE SET) or variable (SET)
Syntax at a glance
modify (XML_DML)
Work example
Apply one XML DML operation to a selected XML instance.
Copy an example document into a variable, run one modify expression, and inspect the returned XML.
Check your work modify changes the XML instance and returns no scalar value.
Practice SQL
Open in SQL FlowDECLARE @doc xml = N'<Order><Item quantity="2" /></Order>'; SET @doc.modify('replace value of (/Order/Item/@quantity)[1] with "3"'); SELECT @doc AS updated_xml;
Open Microsoft Learn for full syntax, permissions, and details for your version.