Microsoft® SQL Server® 2012 Bible

(Ben Green) #1

365


Chapter 14: Using XML Data


14


<ItemNumber>1008</ItemNumber>
<ItemNumber>1009</ItemNumber>
<ItemNumber>1010</ItemNumber>

The where clause fi lters the XQuery expression for item numbers greater than 1005, and the
order by clause orders the nodes in ascending order.

Summary


Anyone reading this book that remembers trying to use XML with SQL Server 2000 should
also remember how much of a pain it was to work with (XML, not SQL Server ). There was
no XML data type in SQL Server then, but XML was quickly gaining popularity. Anyone
remember XHTML?

To the rescue comes SQL Server 2005 with the wonderful XML data type and the ability
to work with XML natively. While it wasn’t perfect (FOR XML EXPLICIT, ugh) and the
performance wasn’t great, it was FAR better than what you were working with previously.

Over the years improvements have been made and performance increased to make it a
solid way to store and work with XML documents and fragments in SQL Server. However,
as mentioned at the beginning of this chapter, very little was added to SQL Server 2012 for
the XML data type, but that doesn’t mean it isn’t valuable.

This chapter covered the XML data type and its associated methods and syntax. You also
spent considerable time discussing XQuery and the FLWOR statements used to easily and
effi ciently query XML as well as the FOR XML clause to format the shape of resulting XML
when querying TDS data.

c14.indd 365c14.indd 365 7/30/2012 4:49:04 PM7/30/2012 4:49:04 PM


http://www.it-ebooks.info
Free download pdf