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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 9: <strong>SQL</strong> <strong>Server</strong> Storage and Index Structures<br />

ON<br />

<strong>SQL</strong> <strong>Server</strong> gives you the option of storing your indexes separately from the data by using the ON option.<br />

This can be nice from a couple of perspectives:<br />

❑ The space that is required for the indexes can be spread across other drives.<br />

❑ The I/O for index operations does not burden the physical data retrieval.<br />

There’s more to this, but this is hitting the area of highly advanced stuff. It is very data and use dependent,<br />

and so we’ll consider it out of the scope of this book.<br />

Creating XML Indexes<br />

XML indexes were first added in <strong>SQL</strong> <strong>Server</strong> 2005. The indexing of something as unstructured as XML<br />

has been a problem that many have tried to solve, but few have done with any real success, so count<br />

your lucky stars that you have this fine tool available if you’re storing XML data. Let’s get to what XML<br />

indexes are about.<br />

This is another of those “chicken or egg?” things, in that we haven’t really looked at XML at all in this<br />

book thus far. Still, I consider this more of an index topic than an XML topic. Indeed, the XML create<br />

syntax supports all the same options we saw in the previous look at the CREATE statement, with the<br />

exception of IGNORE_DUP_KEY and ONLINE. So, for a bit of hyper-fast background:<br />

Unlike the relational data that we’ve been looking at thus far, XML tends to be relatively unstructured.<br />

It utilizes tags to identify data, and can be associated with what’s called a schema to provide type and<br />

validation information to that XML-based data. The unstructured nature of XML requires the notion of<br />

“navigating” or “path” information to find a data “node” in an XML document. Now indexes, on the<br />

other hand, try and provide very specific structure and order to data — this poses something of a<br />

conflict.<br />

You can create indexes on columns in <strong>SQL</strong> <strong>Server</strong> that are of XML type. The primary requirements of<br />

doing this are:<br />

❑ The table containing the XML you want to index must have a clustered index on it.<br />

❑ A “primary” XML index must exist on the XML data column before you can create “secondary”<br />

indexes (more on this in a moment).<br />

❑ XML indexes can be created only on columns of XML type (and an XML index is the only kind<br />

of index you can create on columns of that type).<br />

❑ The XML column must be part of a base table — you cannot create the index on a view.<br />

The Primary XML Index<br />

282<br />

The first index you create on an XML index must be declared as a “primary” index. When you create a<br />

primary index, <strong>SQL</strong> <strong>Server</strong> creates a new clustered index that combines the clustered index of the base<br />

table together with data from whatever XML node you specify.

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

Saved successfully!

Ooh no, something went wrong!