340
Part III: Advanced T-SQL Data Types and Querying Techniques
What’s New with XML in SQL Server 2012
SQL Server 2012 didn’t add any new XML features or enhancements except for adding support for
the new collation option “SC”, or “supplementary characters.” This new option identifi es whether a
collation is UTF-16 aware, and as such means that support for the collation options has been added in
the SQL Types XML schema and other locations where SQL Server exposes, or consumes, information
in an XML context.
With this addition, the XML schema version has been updated to 1.2 and now exposes a new global
attribute called supplementaryCharacters.
This new global attribute can now be found in a few catalog views (sys.xml_schema_components, sys.
xml_schema_attributes, and sys.xml_schema_component_placements), and pre-populated in the
built-in sys.xml_schemas_collection catalog view.
More information on the Supplementary Characters can be found at http://msdn.microsoft.com/
en-us/library/ms180942(v=SQL.110).aspx.
The XML Data Type
Working with XML can be broken into three main categories:
■ (^) Generating XML
■ (^) Querying XML
■ (^) Validating XML
Prior to SQL Server 2008, it was the responsibility of the application layer to produce the
XML, and there was no consistent or defi ned way to produce the XML. Typically, it would
use the XML API functions available in the programming languages to produce the desired
XML, and if you have done it, it wasn’t easy.
Luckily, XML started gaining acceptance, and developers saw more and more need to
produce and consume XML. Developers started to see the benefi t of XML, and today you
see it all over in websites that produce RSS or ATOM feeds. And you can’t forget XML and
(WCF, Windows Communication Foundation) web services, which generate XML documents
containing information to be exchanged.
SQL Server 2000 was a great fi rst step into supporting XML with support for the T-SQL
FOR XML clause. The FOR XML clause transforms the results of a T-SQL query into an
XML stream. This was a huge benefi t for developers who no longer needed to build XML
documents in their applications. In subsequent releases Microsoft made great improvements
to the FOR XML clause to make it easier to produce XML, and you see how the FOR XML
clause works later in the chapter.
c14.indd 340c14.indd 340 7/30/2012 4:49:00 PM7/30/2012 4:49:00 PM
http://www.it-ebooks.info