Work with the SQL Editor

The SQL Editor is a text editing interface for writing, editing, and executing SQL queries, scripts, and statements against your databases. It offers code-specific features, such as syntax highlighting, code completion (IntelliSense), formatting, error detection, code snippets and templates, and navigation tools.

Open the SQL Editor

You can open the SQL Editor by using Database Explorer, the top menu, the standard toolbar, the Start Page, or a keyboard shortcut.

Using Database Explorer

To open the SQL Editor, right-click a required server connection or a database, then select New SQL.

Using the top menu

To open the SQL Editor, do one of the following:

  • Select File > New > SQL.
  • Select File > New > File:
    • In the New File dialog that opens, select SQL Server > SQL File.
    • Click Create.

Using the standard toolbar

To open the SQL Editor, do one of the following:

  • Click New SQL.

  • Click New File New File:

    • In the New File dialog that opens, select SQL Server > SQL File.
    • Click Create.

Using the Start Page

To open the SQL Editor, click SQL Development > SQL Editor.

Using the keyboard shortcut

To open the SQL Editor, press Ctrl+N.

User interface

The SQL Editor consists of the following components:

  • Code pane: The main area where you write, view, edit, navigate, format, and execute SQL code. You can customize this pane to suit your workflow.
  • Indicator margin: A gray column on the left side of the editor that shows markers for breakpoints and bookmarks. Click this margin to add or remove a breakpoint on a specific line.
  • Selection margin: A column between the indicator margin and the code pane. Click to select entire lines of code.
  • Horizontal and vertical scroll bars: Horizontal and vertical scroll bars that let you navigate through code that extends beyond the visible area of the editor.

Toolbar

SQL Editor toolbar

The table describes the SQL Editor toolbar options.

Icon Name Description
Display an Object Member List Display an Object Member List Shows a list of valid database objects, such as databases, tables, and columns.
To insert a selected item into your code, press Tab, type a space, or type a period.
Shortcut: Ctrl+K, Ctrl+L
Display a Parameter Info Display a Parameter Info Shows a list of parameters when you start typing a function or stored procedure and open the parenthesis (.
Shortcut: Ctrl+Shift+Space
Display Quick Info Display Quick Info Shows general information about an identifier when you hover over it.
Shortcut: Ctrl+K, I
Display Word Completion Display Word Completion Suggests possible completions for the word you are typing.
Shortcut: Ctrl+K, W
Refresh Suggestions Refresh Suggestions Updates a list of suggestions to reflect the changes.
Shortcut: Ctrl+Shift+R
Enable/Disable Code Completion for current document Enable/Disable Code Completion for current document Enables or disables the code completion feature for the active document.
Decrease Line Indent Decrease Line Indent Moves the selected lines to the left by one level of indentation—for example, by removing a tab or leading spaces.
Increase Line Indent Increase Line Indent Moves the selected lines to the right by one level of indentation—for example, by adding a tab or a specific number of spaces.
Comment out the selected lines Comment out the selected lines Turns the selected lines into comments, making them non-executable.
Shortcut: Ctrl+K, C
Uncomment the selected lines Uncomment the selected lines Removes comment markers from the selected lines, making the code executable.
Shortcut: Ctrl+K, U
Toggle a bookmark on the current line Toggle a bookmark on the current line Adds or removes a bookmark on the selected line.
Shortcut: Ctrl+K, K
Move the caret to the previous bookmark Move the caret to the previous bookmark Moves the cursor to the previous bookmark in the script.
Shortcut: Ctrl+K, Ctrl+P
Move the caret to the next bookmark Move the caret to the next bookmark Moves the cursor to the next bookmark in the script.
Shortcut: Ctrl+K, Ctrl+N
Clear all bookmarks in the current document Clear all bookmarks in the current document Removes all bookmarks in the active document.
Shortcut: Ctrl+K, L
Format Document Format Document Automatically formats SQL code in the active document.
Shortcut: Ctrl+K, D
Format Current Statement Format Current Statement Applies formatting to the SQL statement at the current cursor location.
Shortcut: Ctrl+K, S
Analyze Code Analyze Code Scans the SQL script to identify syntax errors, logical issues, and best practice violations before execution.

Select text

To select the text in your code, do one of the following:

  • Press Shift together with the navigation keys (Page up, Page down, Home, or End)
  • Press Shift + Alt together with the navigation keys (Page up, Page down, Home, or End)
  • Use the mouse

Fold and unfold code

Code folding lets you temporarily collapse a block of code so only the header or first line remains visible.

To fold your code, on the left margin of the SQL Editor, click the minus sign.

Code unfolding restores collapsed lines, displaying the full content of the code block.

To unfold your code, on the left margin of the SQL Editor, click the plus sign.

To preview the content of the collapsed clause, hover over it.

Code folding

Change font color, size, and style

You can personalize the appearance of SQL code elements, such as TODO lists or comments.

To change font settings:

1. On the top menu, select Tools > Options.

2. Navigate to Environment > Font and Colors.

3. In the Display items list, choose the item you want to modify.

4. Adjust the Font, Size, Foreground color, and Background color as needed.

5. Click OK to apply the changes.

Change font color, size, and style

Change text case

You can change the case of selected text using menu commands or keyboard shortcuts.

Make text uppercase

To make the text uppercase, select the text and do one of the following:

  • On the top menu, select Edit > Advanced > Make Uppercase.
  • Press Ctrl+Shift+U.

Make text lowercase

To make the text lowercase, select the text and do one of the following:

  • On the top menu, select Edit > Advanced > Make Lowercase.
  • Press Ctrl+Shift+L.

Show white space characters

View White Space mode displays spaces and tab characters.

To view white space:

1. Place the cursor anywhere in the editor.

2. On the top menu, select Edit > Advanced > View White Space.

Alternatively, press Ctrl+R, Ctrl+W.

Use word wrap mode

Word Wrap moves any part of a long line that extends beyond the visible width of the SQL Editor onto the next visual line, so you can view the entire line without scrolling horizontally.

To use word wrap mode, do one of the following:

  • On the top menu, select Edit > Advanced > Word Wrap.
  • Press Ctrl+E, W.

Show line numbers

To show line numbers, do one of the following:

  • On the top menu, select Edit > Advanced > Show Line Numbers.
  • On the top menu, select Tools > Options.
    • Navigate to Text Editor > General.
    • Select the Line numbers checkbox.
    • Click OK to apply the changes.

Comment out a block of code

You can temporarily disable a section of SQL code by commenting it out.

To comment out a block:

1. Place the cursor on the line or select the block of code you want to comment.

2. On the top menu, select Edit > Advanced > Toggle Block Comment.

Alternatively, press Ctrl+Shift+/.

Uncomment a block of code

To make a previously commented block executable again, do one of the following:

  • On the top menu, select Edit > Advanced > Toggle Block Comment.
  • Press Ctrl+Shift+/.

Comment a selection

To comment out selected lines of code:

1. Select the line or block of code you want to comment out.

2. Do one of the following:

  • On the top menu, select Edit > Advanced > Comment Selection.

  • On the toolbar, click Comment out the selected lines Comment out the selected lines.

  • Press Ctrl+K, C.

Uncomment a selection

To remove comment markers from selected lines of code:

1. Select the line or block of code you want to uncomment.

2. Do one of the following:

  • On the top menu, select Edit > Advanced > Uncomment Selection.

  • On the toolbar, click Uncomment the selected lines Uncomment the selected lines.

  • Press Ctrl+K, U.

Increase line indent

To move selected lines to the right by one indentation level:

1. Select the lines you want to indent.

2. On the top menu, select Edit > Advanced > Increase Line Indent.

Alternatively, on the toolbar, click Increase Line Indent Increase Line Indent.

Decrease line indent

To move selected lines to the left by one indentation level:

1. Select the lines you want to unindent.

2. On the top menu, select Edit > Advanced > Decrease Line Indent.

Alternatively, on the toolbar, click Decrease Line Indent Decrease Line Indent.

Insert a snippet

To insert a code snippet into your script:

1. Place the cursor where you want to insert a snippet.

2. On the top menu, select Edit > Code Completion > Insert Snippet.

3. In the suggestion list, select the snippet you want to insert.

The snippet template appears where you can modify it as needed.

Add bookmarks

You can add a bookmark to any line in your SQL document to help you quickly navigate the code.

To add a bookmark, do one of the following:

  • On the top menu, select Edit > Bookmarks > Toggle Bookmark.

  • On the toolbar, click Toggle a bookmark on the current line Toggle a bookmark on the current line.

  • Press Ctrl+K, K.

Note

Bookmarks are added to the line where the cursor is positioned.

Add a bookmark

Navigate bookmarks

To move your cursor to the previous bookmark, do one of the following:

  • On the top menu, select Edit > Bookmarks > Previous Bookmark.

  • On the toolbar, click Move the caret to the previous bookmark Move the caret to the previous bookmark.

  • Press Ctrl+K, Ctrl+P.

To move your cursor to the next bookmark, do one of the following:

  • On the top menu, select Edit > Bookmarks > Next Bookmark.

  • On the toolbar, click Move the caret to the next bookmark Move the caret to the next bookmark.

  • Press Ctrl+K, Ctrl+N.

Delete all bookmarks

To remove all bookmarks in the active document, do one of the following:

  • On the top menu, select Edit > Bookmarks > Clear Bookmarks.

  • On the toolbar, click Clear all bookmarks in the current document Clear all bookmarks in the current document.

  • Press Ctrl+K, L.

Outline code blocks

Use code outlining to collapse or expand logical blocks in your SQL scripts, such as BEGIN...END sections, stored procedures, functions, or multi-line queries. This feature helps you focus on the structure while hiding code details when needed.

Collapse or expand code blocks

To collapse or expand all blocks, on the top menu, select Edit > Outlining > Toggle All Outlining, or press Ctrl+M, M.

To collapse or expand a specific block of code, select Edit > Outlining > Toggle Outline Expansion, or press Ctrl+M, L.

Manage outlining behavior

To stop outlining and remove all collapsible regions, select Edit > Outlining > Stop Outlining, or press Ctrl+M, P.

To enable automatic detection of collapsible regions, select Edit > Outlining > Start Automatic Outlining.

Configure the SQL Editor settings

To configure the SQL Editor settings, do one of the following:

  • On the top menu, select Tools > Options > Text Editor.
  • Right-click anywhere in the SQL Editor and select Settings > Options.

Configure SQL Editor settings

Status bar

The status bar displays information regarding the current connection, including a connection status, server, username, and selected database.

Status bar

When you execute a query, the query execution status is shown instead of the connection status. The query execution time also appears in the status bar.

Status bar for the executed query