Writing, Analyzing, and Editing Scripts with SQL Server Management Studio

SQL Server Management Studio includes language-specific code editors for editing Transact-SQL, XQuery, MDX, DMX, XMLA, and SQL Server Compact 3.5 SP2 queries.

Features

SQL Server Management Studio code editors include the following features:

  • Templates that can be used to speed authoring of scripts for scripts for SQL Server Database Engine, Analysis Services, and SQL Server Compact 3.5 SP2. Templates are files that include the basic structure of the statements needed to create objects in a database.

  • Color coding of syntax to improve the readability of complex statements.

  • A graphical query designer for drag-and-drop creation of queries.

  • Presentation of query windows as either tabs in the document window, or in separate documents.

  • Presentation of query results in either a grid or text window or redirected to a file.

  • Display of result grids as separate tabbed windows.

  • Graphical display of Showplan information showing the logical steps built into the execution plan of a Transact-SQL statement.

  • A feature-rich text editing environment supporting find and replace, bulk commenting, custom fonts and colors, and line numbering. Some types of editors contain additional features like outlining and auto-complete.

  • SQLCMD Mode for executing scripts with operating-system commands.

    When you select this option, be aware of the following limitations:

    • IntelliSense in the Database Engine Query Editor is turned off.

    • Because Query Editor does not run from the command line, you cannot pass in command-line parameters such as variables.

    • Because Query Editor cannot respond to operating-system prompts, you must be careful not to run interactive statements.

Note

Enabling IntelliSense for large Transact-SQL scripts can reduce the performance of slow computers. For information about how to limit the size of Transact-SQL scripts for which IntelliSense is enabled, see Options (Text Editor/Transact-SQL/IntelliSense).

Note

The SQL Server Management Studio SQL Server Compact Query Editor does not support SQL Server Compact 4.0.

Components

The query editors include the following windows:

  • Query Editor. This window is used to write and execute scripts.

  • Results. This window is used to view the results of a query. The window can display the results in grid or in text.

  • Messages. This window displays errors, warnings, and informational messages that are returned by the server when a script is run. The list of messages does not change until the script is run again.

  • Error List. This window displays syntax and semantic errors found by the IntelliSense feature in the Database Engine Query Editor. The list of errors changes dynamically as you edit Transact-SQL scripts. The Error List only displays errors from the Database Engine Query Editor; it does not display errors from the other editors.

  • Client Statistics. This window displays information about the query execution grouped into categories. When Include Client Statistics is selected from the Query menu, a Client Statistics window is displayed upon query execution. Statistics from successive query executions are listed along with the average values. Select Reset Client Statistics from the Query menu to reset the average.

The following table lists SQL Server Books Online topics related to the code editor.

Topic

Description

Using SQL Server Management Studio Templates

Contains information about templates and creating custom templates.

Editor Convenience Commands and Features

Includes topics on features such as code outlining, line numbering, hyperlinks in comments, sguiggles, word wrap, and more.

SQL Server Management Studio Keyboard Shortcuts

Includes a list of the keyboard shortcuts available in the code editor.

How to: Associate File Extensions to a Code Editor

Explains how to configure SQL Server Management Studio to open a designated code editor based on a file extension.

Editing Scripts and Files in SQL Server Management Studio

Contains links to pages that describe many configuration options for the code editor.

How to: Change Font Color, Size, and Style

Describes how to customize the appearance of text in the code editor.

Error List Window (Management Studio)

Describes how the Database Engine Query Editor displays error information.

To access a SQL Server Management Studio Query Editor

  • On the File menu, click New, and then click File.

    The New File dialog box appears.

    Click the type of query you want to create. For example, to create a Transact-SQL Query, click Database Engine Query.

    The Query Editor window appears.

  • On the SQL Server Management Studio toolbar, click the button for the query editor that you want to open. For example, to create an XMLA query, click Analysis Services XMLA Query.

    The Query Editor window appears.

To access the Database Engine Query Editor from Template Explorer

  1. On the View menu, click Template Explorer.

    The Template Explorer window appears in the lower right.

  2. Double-click a template to open a Database Engine Query window with the text of the template. For example, to open a CREATE DATABASE template, open the SQL Server Templates folder, open the Databases folder, and double-click create database.

To view the code editor in full-screen mode

  • In a code editor window, press SHIFT+ALT+ENTER, to toggle in and out of full-screen mode.

To view the Management Studio Error List window

  • To view the Management Studio Error List window, you can use either of the following methods:

    • On the View menu, click Error List.

    • Enter the CTRL+\, CTRL+E keyboard shortcut.