insert (XML DML)
XML DML insert (inside modify())
What changes
- Input
- XML nodes or values to insert
- Output or change
- the xml instance being modified
Syntax at a glance
insert Expression1 ( {as first | as last} into | after | before Expression2 )
Work example
Add a child node or attribute when a document needs a small structured update.
Choose before, after, or into from the desired position and target exactly one parent node.
Check your work The insert expression must match the selected XML location and node kind.
Practice SQL
Open in SQL FlowDECLARE @doc xml = N'<Order />'; SET @doc.modify('insert <Item code="A1" /> into (/Order)[1]'); SELECT @doc AS updated_xml;
Open Microsoft Learn for full syntax, permissions, and details for your version.