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.

Chapter 14: Transactions and Locks<br />

level (not check every row or page lock on the table) to determine if a transaction can safely lock the<br />

entire table. Intent locks come in three different varieties:<br />

❑ Intent shared lock: A shared lock has been, or is going to be, established at some lower point in<br />

the hierarchy. For example, a page is about to have a page-level shared lock established on it.<br />

This type of lock applies only to tables and pages.<br />

❑ Intent exclusive lock: This is the same as intent shared, but with an exclusive lock about to be<br />

placed on the lower-level item.<br />

❑ Shared with intent exclusive lock: A shared lock has been, or is about to be, established lower<br />

down the object hierarchy, but the intent is to modify data, so it will become an intent exclusive<br />

at some point.<br />

Schema Locks<br />

These come in two flavors:<br />

❑ Schema modification lock (Sch-M): A schema change is being made to the object. No queries or<br />

other CREATE, ALTER, or DROP statements can be run against this object for the duration of the<br />

Sch-M lock.<br />

❑ Schema stability lock (Sch-S): This is very similar to a shared lock; this lock’s sole purpose is to<br />

prevent a Sch-M, since there are already locks for other queries (or CREATE, ALTER, or DROP<br />

statements) active on the object. This is compatible with all other lock types.<br />

Bulk Update Locks<br />

A bulk update lock (BU) is really just a variant of a table lock with one little (but significant) difference. Bulk<br />

update locks will allow parallel loading of data — that is, the table is locked from any other normal activity<br />

(T-<strong>SQL</strong> statements), but multiple BULK INSERT or bcp operations can be performed at the same time.<br />

Lock Compatibility<br />

440<br />

The table that follows shows the compatibility of the resource lock modes (listed in increasing lock<br />

strength). Existing locks are shown by the columns, requested locks by the rows:<br />

IS S U IX SIX X<br />

Intent Shared (IS) YES YES YES YES YES NO<br />

Shared (S) YES YES YES NO NO NO<br />

Update (U) YES YES NO NO NO NO<br />

Intent Exclusive (IX) YES NO NO YES NO NO<br />

Shared with Intent Exclusive (SIX) YES NO NO NO NO NO<br />

Exclusive (X) NO NO NO NO NO NO

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

Saved successfully!

Ooh no, something went wrong!