XMLNAMESPACES is a clause (introduced with the WITH keyword in SQL Server and as part of the SELECT list in Oracle) that maps namespace URIs to prefixes or designates a default namespace. The mapping is scoped only to the statement in which the clause appears, letting you:- Qualify element and attribute names when constructing XML with FOR XML PATH, RAW, AUTO, or EXPLICIT.- Reference those prefixes inside value(), query(), exist(), and other XQuery methods.- Avoid hard-coding xmlns declarations in string literals.The clause does not persist any metadata, change global settings, or register schemas. If the same prefix appears twice, the last declaration in the list wins. Declaring a DEFAULT namespace makes any un-prefixed element or attribute belong to that URI.
prefix
(string) - The alias used in element or attribute names.namespace_uri
(string) - The namespace URI enclosed in single quotes.DEFAULT
(keyword) - Indicates that the following URI is the default namespace for un-prefixed nodes.FOR XML, XQuery, XML Data Type, WITH XMLSCHEMA, OPENXML
SQL Server 2005
DEFAULT assigns a namespace URI to all un-prefixed nodes, while a named prefix requires you to prepend the prefix (e.g., s:order) when referencing the element or attribute.
It only influences FOR XML output and XQuery methods. If neither appears in the statement, the clause has no observable effect.
Declare DEFAULT NULL inside the XMLNAMESPACES list to remove any previously set default for that statement.
No. Use a single WITH XMLNAMESPACES clause per statement; list all mappings inside it.