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.

more administrator oriented and usually used on an ad hoc basis to deal with very specific problems.<br />

The core elements here should, however, be part of your regular maintenance planning.<br />

We’ll start by looking at a couple of top parameters and then look at the options that are part of your<br />

larger maintenance-planning needs.<br />

Index Name<br />

We can name a specific index if you want to maintain one specific index, or use ALL to indicate that you<br />

want to perform this maintenance on every index associated with the named table.<br />

Table or View Name<br />

Pretty much just what it sounds like — the name of the specific object (table or view) that you want to<br />

perform the maintenance on. Note that it needs to be one specific table (you can feed it a list and say “do<br />

all of these please!”).<br />

REBUILD<br />

This is the “industrial-strength” approach to fixing an index. If you run ALTER INDEX with this option,<br />

the old index is completely thrown away and a new one reconstructed from scratch. The result is a truly<br />

optimized index, where every page in both the leaf and non-leaf levels of the index has been reconstructed<br />

as you have defined it (either with defaults or using switches to change things like the fillfactor). If<br />

the index in question is a clustered index, then the physical data is also reorganized.<br />

By default, the pages will be reconstituted to be full, minus two records. Just as with the CREATE TABLE<br />

syntax, you can set the FILLFACTOR to be any value between 0 and 100. This number will be the percent<br />

that your pages are full once the database reorganization is complete. Remember, though, that as your<br />

pages split, your data will still be distributed 50-50 between the two pages — you cannot control the fill<br />

percentage on an ongoing basis unless you regularly rebuild the indexes.<br />

Careful on this one. As soon as you kick off a rebuild, the index you are working on is essentially<br />

gone until the rebuild is complete. Any queries that rely on that index may become exceptionally<br />

slow (potentially by orders of magnitude). This is the sort of thing you want to test on an offline system<br />

first to have an idea how long it’s going to take, and then schedule to run in off hours (preferably with<br />

someone monitoring it to be sure it’s back online when peak hours come along).<br />

This one can have major side effects while it runs, and thus it falls squarely in the domain of the database<br />

administrator in my not so humble opinion.<br />

DISABLE<br />

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

This one does what it says, only in somewhat drastic fashion. It would be nice if all this command did<br />

was take your index offline until you decided further what you wanted to do, but instead, it essentially<br />

marks the index as unusable. Once an index has been disabled, it must be rebuilt (not reorganized, but<br />

rebuilt) before it will be active again.<br />

This is one you’re very, very rarely going to do yourself (you would more likely just drop the index). It is<br />

far more likely to happen during an <strong>SQL</strong> <strong>Server</strong> upgrade or some other oddball situation.<br />

289

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

Saved successfully!

Ooh no, something went wrong!