SQL XML Modes: RAW, AUTO and PATH
-
Upload
aaron-buma -
Category
Software
-
view
580 -
download
3
Transcript of SQL XML Modes: RAW, AUTO and PATH
XML Modes:RAW, AUTO and PATH
Presentation by Aaron BumaDevelopment DBA
Session Overview
•FOR XML Clause
•RAW – Including ROW, ROOT and ELEMENTS•AUTO•PATH – With adding attributes
and nameless fields
FOR XML• Required for using RAW, AUTO, EXPLICIT PATH• Transforms result set into XML in a single result
FOR XML - RAW• Each row is turned into an XML node named “row”• Each column is an attribute
• You can replace “row” with your own name
• To make it well formed, add the “root” element
FOR XML – RAW, continued• If you don’t want column values as attributes use
“ELEMENTS”
DEMO
• XML RAW – with ROW, ROOT and ELEMENTS
FOR XML – AUTO• Similar to RAW, but uses table name/alias vs “row”
• ROW, ROOT and ELEMENTS can be used
DEMO
• XML AUTO
FOR XML – PATH• Like RAW, but data is elements instead of attributes
• ROW, ROOT and ELEMENTS can be used
FOR XML – PATH, continued• With PATH, you can put values in attributes: @alias
• Adding “/” in the column alias forces nesting
FOR XML – PATH, continued• Using ‘*’ puts value as element at that level– It’s a “nameless” field because you are not labling it
DEMO
• XML PATH– Forced nesting– Nameless fields
Questions?
• RAW – Including ROW, ROOT and ELEMENTS• AUTO• PATH – With adding attributes
and nameless fields
Presentation Recording, Slides and Scripts– Available at: http://www.AaronBuma.com