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.

The older DBCC commands are still supported for backward compatibility, but <strong>Microsoft</strong> may remove<br />

them at any time, so you should be proactive about updating those scripts should you come across any.<br />

ALTER INDEX is the workhorse of database maintenance. We addressed this somewhat back in Chapter 9,<br />

but let’s revisit this one, and then look at how to get it scheduled.<br />

ALTER INDEX<br />

The command ALTER INDEX is somewhat deceptive in what it does. While most ALTER commands have<br />

been about changing the definition of our object — we ALTER tables to add or disable constraints and<br />

columns, for example — ALTER INDEX is different; it is all about maintenance and zero about structure.<br />

If you need to change the makeup of your index, you still need to either DROP and CREATE it, or you<br />

need to CREATE and use the with the DROP_EXISTING=ON option.<br />

An abbreviated version of the ALTER INDEX syntax looks like this:<br />

ALTER INDEX { | ALL }<br />

ON <br />

{ REBUILD<br />

[ [ WITH ( [ ,...n ] ) ]<br />

| [ PARTITION = <br />

[ WITH ( <br />

[ ,...n ] ) ] ] ]<br />

| DISABLE<br />

| REORGANIZE<br />

[ PARTITION = ]<br />

[ WITH ( LOB_COMPACTION = { ON | OFF } ) ]<br />

| SET ( [ ,...n ] )<br />

}<br />

[ ; ]<br />

A fair amount on this is fairly detailed “Realm of the advanced DBA” stuff — usually used on an ad hoc<br />

basis to deal with very specific problems, but there are some core elements here that should be part of<br />

our regular maintenance planning. We’ll start by looking at a couple of top parameters and then look at<br />

the options that are part of our larger maintenance planning needs.<br />

Index Name<br />

You 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 perform<br />

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

of these please!”)<br />

REBUILD<br />

Chapter 19: Playing Administrator<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 reconstructed from scratch. The result is a truly optimized<br />

581

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

Saved successfully!

Ooh no, something went wrong!