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.

FILLFACTOR<br />

When <strong>SQL</strong> <strong>Server</strong> first creates an index, the pages are, by default, filled as full as they can be, minus two<br />

records. You can set the FILLFACTOR to be any value between 1 and 100. This number will determine<br />

how full your pages are as a percentage, once index construction is completed. Keep in mind, however,<br />

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

control the fill percentage on an ongoing basis other than regularly rebuilding the indexes (something<br />

you should do).<br />

We use a FILLFACTOR when we need to adjust the page densities. Think about things this way:<br />

❑ If it’s an OLTP system, you want the FILLFACTOR to be low.<br />

❑ If it’s an OLAP or other very stable (in terms of changes — very few additions and deletions)<br />

system, you want the FILLFACTOR to be as high as possible.<br />

❑ If you have something that has a medium transaction rate and a lot of report-type queries<br />

against it, then you probably want something in the middle (not too low, not too high).<br />

If you don’t provide a value, then <strong>SQL</strong> <strong>Server</strong> will fill your pages to two rows short of full, with a minimum<br />

of one row per page (for example, if your row is 8,000 characters wide, you can fit only one row<br />

per page, so leaving things two rows short wouldn’t work).<br />

IGNORE_DUP_KEY<br />

The IGNORE_DUP_KEY option is a way of doing little more than circumventing the system. In short, it<br />

causes a unique constraint to have a slightly different action from that which it would otherwise have.<br />

Normally, a unique constraint, or unique index, does not allow any duplicates of any kind — if a transaction<br />

tried to create a duplicate based on a column that is defined as unique, then that transaction would<br />

be rolled back and rejected. After you set the IGNORE_DUP_KEY option, however, you’ll get mixed behavior.<br />

You will still receive an error message, but the error will only be of a warning level. The record is still not<br />

inserted.<br />

This last line — the record is still not inserted — is a critical concept from an IGNORE_DUP_KEY<br />

standpoint. A rollback isn’t issued for the transaction (the error is a warning error rather than a critical<br />

error), but the duplicate row will have been rejected.<br />

Why would you do this? Well, it’s a way of storing unique values without disturbing a transaction that<br />

tries to insert a duplicate. For whatever process is inserting the would-be duplicate, it may not matter at<br />

all that it’s a duplicate row (no logical error from it). Instead, that process may have an attitude that’s<br />

more along the lines of, “Well, as long as I know there’s one row like that in there, I’m happy — I don’t<br />

care whether it’s the specific row that I tried to insert or not.”<br />

DROP_EXISTING<br />

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

If you specify the DROP_EXISTING option, any existing index with the name in question will be dropped<br />

prior to construction of the new index. This option is much more efficient than simply dropping and<br />

re-creating an existing index when you use it with a clustered index. If you rebuild an exact match of the<br />

existing index, <strong>SQL</strong> <strong>Server</strong> knows that it need not touch the non-clustered indexes, while an explicit<br />

drop and create would involve rebuilding all non-clustered indexes twice in order to accommodate<br />

279

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

Saved successfully!

Ooh no, something went wrong!