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.

Secondary XML Indexes<br />

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

Nothing special here — much as non-clustered indexes point to the cluster key of the clustered index,<br />

secondary XML indexes point at primary XML indexes. Once you create a primary XML index, you can<br />

create up to 248 more XML indexes on that XML column.<br />

Implied Indexes Created with Constraints<br />

I guess I call this one “index by accident.” It’s not that the index shouldn’t be there — it has to be there if<br />

you want the constraint that created the index. It’s just that I’ve seen an awful lot of situations where the<br />

only indexes on the system were those created in this fashion. Usually, this implies that the administrators<br />

and/or designers of the system are virtually oblivious to the concept of indexes.<br />

However, you’ll also find yet another bizarre twist on this one — the situation where the administrator<br />

or designer knows how to create indexes, but doesn’t really know how to tell what indexes are already on<br />

the system and what they are doing. This kind of situation is typified by duplicate indexes. As long as<br />

they have different names, <strong>SQL</strong> <strong>Server</strong> will be more than happy to create them for you.<br />

Implied indexes are created when one of two constraints is added to a table:<br />

❑ A PRIMARY KEY<br />

❑ A UNIQUE constraint (aka, an alternate key)<br />

We’ve seen plenty of the CREATE syntax up to this point, so I won’t belabor it; however, it should be<br />

noted that all the options except for {CLUSTERED|NONCLUSTERED} and FILLFACTOR are not allowed<br />

when creating an index as an implied index to a constraint.<br />

Creating Indexes on Sparse and Geospatial Columns<br />

These are definitely beyond the scope of a beginning book, but sparse columns and data with a geospatial<br />

data type can both have special indexes created on them. Again, keep this in mind if you have application<br />

for these special-needs types of columns.<br />

Choosing Wisely: Deciding What Index<br />

Goes Where and When<br />

By now, you’re probably thinking to yourself, “Gee, I’m always going to create clustered indexes!” There<br />

are plenty of good reasons to think that way. Just keep in mind that there are also some reasons not to.<br />

Choosing what indexes to include and what not to can be a tough process, and in case that wasn’t<br />

enough, you have to make some decisions about what type you want them to be. The latter decision is<br />

made simultaneously easier and harder by the fact that you can only have one clustered index. It means<br />

that you have to choose wisely to get the most out of it.<br />

283

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

Saved successfully!

Ooh no, something went wrong!