Microsoft® SQL Server® 2012 Bible

(Ben Green) #1

103


Chapter 5: SQL Server Management and Development Tools


5


Query ➪ Execute Query, click the Run Query toolbar button, use the F5 key, or press Ctrl+E.
Because batches tend to be long, and it’s often preferable to execute a single T-SQL com-
mand or a portion of the batch for testing or stepping through the code, the SQL Server
team provides you with a convenient feature. If no text is highlighted, the entire batch
executes. If text is highlighted, only that text executes.

FIGURE 5-10
You can view and set Advanced and ASNI query options using the Query Options dialog.
This view shows the Advanced Query Options.

Chapter 16, “Programming with T-SQL,” discusses this more, but technically, when Query
Editor sends the script to SQL Server, it breaks it up into smaller batches separated by the
Batch Separator — go.

It’s worth pointing out that the Parse Query menu command and toolbar button checks only
the SQL code. It does not check object names (tables, columns, stored procedures, and so
on). This actually is a feature, not a bug. By not including the object name–checking in the
syntax check, SQL Server permits batches that create objects and then reference them.

The T-SQL batch executes within the context of a current database. The current database
displays and may be changed, within the database combo box in the toolbar.

Results!
The results of the query display in the bottom pane, along with the Messages tab, and
optionally the Client Statistics, or Query Execution Plan tabs. The Results tab format may
be either text or grid; you can switch using Ctrl+T or Ctrl+D, respectively. The new format
will be applied to the next batch execution.

c05 July 23, 2012 11:44 AM V1

c05.indd 103c05.indd 103 7/30/2012 4:14:51 PM7/30/2012 4:14:51 PM


http://www.it-ebooks.info
Free download pdf