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.

Also:<br />

❑ The Sch-S is compatible with all lock modes except the Sch-M.<br />

❑ The Sch-M is incompatible with all lock modes.<br />

❑ The BU is compatible only with schema stability and other bulk update locks.<br />

Specifying a Specific Lock Type — Optimizer Hints<br />

Sometimes you want to have more control over the way the locking goes, either in your query or perhaps<br />

in your entire transaction. You can do this by making use of what are called optimizer hints.<br />

Optimizer hints are ways of explicitly telling <strong>SQL</strong> <strong>Server</strong> to escalate a lock to a specific level. They are<br />

included right after the name of the table (in your <strong>SQL</strong> Statement) that they are to affect.<br />

Optimizer hints are seriously on the advanced side of things. They are often abused by people who are<br />

experienced <strong>SQL</strong> <strong>Server</strong> developers, and they are not to be trifled with.<br />

Think of it this way — <strong>Microsoft</strong> has invested literally millions of dollars in such things as their query<br />

optimizer and knowing what locks to utilize in what situations. Query hints are meant to adjust for the<br />

little things the optimizer may not know about, but in the vast majority of cases you are not going to<br />

know more than their optimizer team did. Shy away from these until the later stages of your <strong>SQL</strong> <strong>Server</strong><br />

learning process (and I promise, I’ll cover them well in the Professional version of this book).<br />

Determining Locks Using the Management Studio<br />

Chapter 14: Transactions and Locks<br />

Perhaps the nicest way of all to take a look at your locks is using the Management Studio. The Management<br />

Studio will show you locks in two different sorts — by process ID or by object — utilizing the Activity<br />

Monitor.<br />

To make use of the Management Studio’s lock display, just navigate to the ➪ Activity Monitor<br />

node of the Management Studio, where is the top level node for the server you want to monitor<br />

activity on. <strong>SQL</strong> <strong>Server</strong> should come up with a new window that looks something like Figure 14-3.<br />

Just expand the node that you’re interested in (the Overview section is expanded by default — I’ve manually<br />

expanded the Processes section) and you can scroll around to find a large number of metrics —<br />

including whatever locks are currently active on the system.<br />

Perhaps the coolest feature of the Activity Monitor is that when you right-click on a specific process in<br />

the Process window, you get the option of easily starting a <strong>SQL</strong> Profiler trace against that particular<br />

process. This can be very handy when you are troubleshooting a variety of situations.<br />

441

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

Saved successfully!

Ooh no, something went wrong!