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 />

ALTER INDEX<br />

288<br />

The ALTER INDEX command is somewhat deceptive in what it does. Up until now, ALTER commands<br />

have always been about changing the definition of your object. You ALTER tables to add or disable constraints<br />

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

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

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

As you saw earlier in the chapter, <strong>SQL</strong> <strong>Server</strong> gives you an option for controlling just how full your leaf<br />

level pages are and, if you choose, another option to deal with non-leaf level pages. Unfortunately, these<br />

are proactive options. They are applied once, and then you need to reapply them as necessary by<br />

rebuilding your indexes and reapplying the options.<br />

In the upcoming section on maintenance, we’ll look more at the wheres and whys of utilizing this command,<br />

but for now, take it on faith that you’ll use maintenance commands like ALTER INDEX as part of<br />

your regular maintenance routine.<br />

The ALTER INDEX syntax looks like this:<br />

ALTER INDEX { | ALL }<br />

ON <br />

{ REBUILD<br />

[ [ WITH (<br />

[ PAD_INDEX = { ON | OFF } ]<br />

| [[,] FILLFACTOR = <br />

| [[,] SORT_IN_TEMPDB = { ON | OFF } ]<br />

| [[,] IGNORE_DUP_KEY = { ON | OFF } ]<br />

| [[,] STATISTICS_NORECOMPUTE = { ON | OFF } ]<br />

| [[,] ONLINE = { ON | OFF } ]<br />

| [[,] ALLOW_ROW_LOCKS = { ON | OFF } ]<br />

| [[,] ALLOW_PAGE_LOCKS = { ON | OFF } ]<br />

| [[,] MAXDOP = <br />

) ]<br />

| [ PARTITION = <br />

[ WITH ( <br />

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

| DISABLE<br />

| REORGANIZE<br />

[ PARTITION = ]<br />

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

| SET ([ ALLOW_ROW_LOCKS= { ON | OFF } ]<br />

| [[,] ALLOW_PAGE_LOCKS = { ON | OFF } ]<br />

| [[,] IGNORE_DUP_KEY = { ON | OFF } ]<br />

| [[,] STATISTICS_NORECOMPUTE = { ON | OFF } ]<br />

)<br />

} [ ; ]<br />

Several of the options are common to the CREATE INDEX command, so I will skip redefining those particular<br />

ones here. Beyond that, a fair amount of the ALTER-specific options are fairly detailed and relate<br />

to dealing with things like fragmentation (we’ll get to fragmentation and maintenance shortly) or are

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

Saved successfully!

Ooh no, something went wrong!