17.06.2013 Views

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

XML functionality was a relatively late addition to <strong>SQL</strong> <strong>Server</strong>. Indeed, it first appeared as a downloadable<br />

add-on to <strong>SQL</strong> <strong>Server</strong> 7.0. What’s more, a significant part of the functionality was originally more an<br />

addition to Internet Information <strong>Server</strong> (IIS) than to <strong>SQL</strong> <strong>Server</strong>.<br />

With <strong>SQL</strong> <strong>Server</strong> 2000, the XML side of things moved to what <strong>Microsoft</strong> called a “Web Release” model,<br />

and was updated several times. With <strong>SQL</strong> <strong>Server</strong> 2005, XML finished moving into the core product.<br />

While most of the old functionality remains supported, <strong>SQL</strong> <strong>Server</strong> continues to add more core features<br />

that makes XML an integral part of things rather than the afterthought that XML sometimes seemed to<br />

be in early releases.<br />

What functionality? Well, in <strong>SQL</strong> <strong>Server</strong> <strong>2008</strong> XML comes to the forefront in several places:<br />

❑ Support for multiple methods of selecting data out of normal columns and receiving them in<br />

XML format<br />

❑ Support for storing XML data natively within <strong>SQL</strong> <strong>Server</strong> using the XML data type<br />

❑ Support for querying data that is stored in its original XML format using XQuery (a special<br />

query language for XML) and other methods<br />

❑ Support for enforcing data integrity in the data being stored in XML format using XML schemas<br />

❑ Support for indexing XML data<br />

❑ Support for hierarchical data — granting special support for the tree-like structures that are so<br />

common in XML data<br />

And this is just the mainstream stuff.<br />

The support for each of these often makes use of several functional areas of XML support, so let’s look at<br />

XML support one piece at a time.<br />

Defining a Column as Being of XML Type<br />

We’ve already seen the most basic definition of an XML column. For example, if we examined the most<br />

basic definition of the Production.ProductModel table in the AdventureWorks<strong>2008</strong> database, it would<br />

look something like this:<br />

CREATE TABLE Production.ProductModel<br />

(<br />

ProductModelID int IDENTITY(1,1) PRIMARY KEY NOT NULL,<br />

Name dbo.Name NOT NULL,<br />

CatalogDescription xml NULL,<br />

Instructions xml NULL,<br />

rowguid uniqueidentifier ROWGUIDCOL NOT NULL,<br />

ModifiedDate datetime NOT NULL<br />

CONSTRAINT DF_ProductModel_ModifiedDate DEFAULT (GETDATE()),<br />

);<br />

So, let’s ask ourselves what we have here in terms of our two XML columns.<br />

Chapter 16: A Brief XML Primer<br />

1. We have defined them as XML, so we will have our XML data type methods available to us<br />

(more on those coming up soon).<br />

487

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!