16.1. The XML Data Type

The addition of the XML data type signals the end of what has been, to me, a rather long road. For the first time, SQL Server takes data that is in XML format and recognizes it as truly being XML data. In previous versions, there were an increasing number of ways to address XML data, but all of it was done from the foundation of basic character data. XML now recognizes XML as XML and that opens up a host of new possibilities from indexing to data validation.

The number of different things going on here is massive. Among the various things that we need to talk about when discussing the XML data type include:

  • Schema collections — A core concept of XML is the notion of allowing XML to be associated with schema documents. XML schemas define the rules that allow us to determine whether our XML is "valid" (that is, does it meet the rules for that this particular kind of XML document is supposed to do). XML schema collections in SQL Server are a way of storing schemas and allowing SQL Server to know that is what they are — validation documents. You can associate instances of XML data (column data or variables for example) with XML schemas, and SQL Server will apply the schema to each instance of that XML to determine whether it is valid XML or not.

  • Enforcing constraints — We've already dealt with the idea of requiring a column to meet certain criteria before we'll let it into our table, but what about XML? XML allows for multiple pieces of discrete data to be stored ...

Get Professional SQL Server™ 2005 Programming now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.