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.

command-line scripting. By default, these special script commands are not available in the Query window.<br />

Turning sqlcmd mode on activates the special sqlcmd scripting options even in the Query window.<br />

Show Execution Plan<br />

Every time you run a query, <strong>SQL</strong> <strong>Server</strong> parses your query into its component parts and then sends it to<br />

the query optimizer. The query optimizer is the part of <strong>SQL</strong> <strong>Server</strong> that figures out the best way to run<br />

your query to balance fast results with minimum impact to other users. When you use the Show Estimated<br />

Execution Plan option, you receive a graphical representation and additional information about how<br />

<strong>SQL</strong> <strong>Server</strong> plans to run your query. Similarly, you can turn on the Include Actual Execution Plan option.<br />

Most of the time, this will be the same as the estimated execution plan, but you will occasionally see<br />

differences here due to changes that the optimizer decides to make while running the query, as well as<br />

changes in the actual cost of running the query versus what the optimizer thinks is going to happen.<br />

Let’s see what a query plan looks like in our simple query. Click the Include Actual Execution Plan<br />

option, and execute the query again, as shown in Figure 2-13.<br />

Figure 2-13<br />

Chapter 2: Tools of the Trade<br />

Be aware that the Query window always utilizes the <strong>SQL</strong>NativeClient connection<br />

method (even when operating in sqlcmd mode), whereas the actual sqlcmd utility<br />

will use an OLE DB connection. The result is that you may see slight differences<br />

in behavior between running a script using sqlcmd versus using sqlcmd from the<br />

Query window. These tend to be corner case differences, and are rarely seen and<br />

generally innocuous.<br />

37

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

Saved successfully!

Ooh no, something went wrong!