How to ... Create and edit queries

There are several ways to create a new query each of which uses a different context to determine which database to create the query against.

When creating a new query from the File-New menu you will be presented with a list of available servers and databases. Selecting a different server in the list changes the database list to reflect those available on that server.

Double click the database or click OK to create a new query.

Alternatively you can select a database (or any node under the database) in the Workspace and click the New Query button on the Workspace toolbar. This will open a query using that database.

When creating a new query using the main toolbar button, if an existing query window is open the query will be created against the same database as that used by the open query. If no query window is available a dialog is displayed allowing you to select the server and database you would like to connect to.

Tab tool tips

When you have multiple queries open you can hover the mouse over each tab to get a tool tip summarizing the query text. This allows you to see which window has which query without switching to each tab separately. How much of the query's text is displayed in the tool tip can be changed (see changing options and preferences for more details).

Status information

Once a query is open you will get a window comprising of status information along the top and the editor filling the rest of the window.

The status information included the following:

Query Editor

The query editor provides all the standard editing features you would expect such and the ability to Cut, Copy, and Paste text. You can also Delete text; this is similar to Cut but does not place the removed text on the clipboard. You can also Undo and Redo an unlimited number of changes.

In addition to the standard editing features you can move and copy text using drag and drop. To move text select the desired range and drag it to a new location. To copy text select the desired range and drag it to a new location holding down the Ctrl key as you do so.

To select a word you can double click on it; to select a line you can click to the left of the line; and to select the whole document you double click to the left of any line.

As an aid to copying text from one window to another you can select text and use the Copy to New Window command. This is equivalent to copying text, creating a new query against the same database and pasting the text.

Syntax highlighting

SQL Visualizer highlights the query text to help make it easier to read and help you spot typographical errors.

Highlighted items include comments, keywords, variables, system functions, numbers, strings, and operators.

The editor also indicates matching brackets and BEGIN/END statements.

Indenting

This also illustrates tab guide lines. Whenever you use a tab the editor will display a guide line so that you can easily trace nested statements.

To indent a group of lines together select the lines to indent and press the tab key or the indent toolbar button.

Document line modification indicators

As you make changes to the query an indicator against each line helps you to keep track of what changes have been made.

When a query is opened no indicator is displayed. When you make changes the changed line turns yellow. When you save the query the changed lines show as green to indicate the changes have been saved.

When you execute a query or part of a query the indicator turns blue to show which lines have been executed.

You can switch off this feature in the options dialog (see changing options and preferences for more details).

Multiple document views

Sometimes when a query is very long you may wish to view 2 different sections of the query at the same time. By using the spit view you can split the editor to display 2 views on the same text, allowing you to keep one part of the query in the top view, and scroll to another part of the same query in the bottom view.

To create this split view drag the splitter down from the top of the editor.

To return to a single view drag the splitter to the top of the editor.

This same process can be used to create 2 vertical views, or a 2 by 2 horizontal and vertical view.

Commenting

To comment a series of lines select the lines and click the Comment toolbar button.

To uncomment lines select the desired lines and click the Uncomment toolbar button.

Bookmarks

Bookmarks allow you to indicate query lines of special interest navigating to them to quickly without the need to search through your code.

To set a bookmark click the bookmark toolbar button. A bookmark icon is set against that line.

To remove an existing bookmark place the caret on the line with the bookmark and click the bookmark toolbar button. This toggles the bookmark removing it from the line.

To navigate bookmarks just click the Next Bookmark or Previous Bookmark toolbar buttons. Navigating back from the first bookmark goes to the last bookmark in the query. Navigating to the next bookmark from the last bookmark goes to the first bookmark in the query.

You can clear all bookmarks in a query by clicking the Clear Bookmarks button.

View White Space

This allows you to toggle the display of white space. Sometimes you may need to distinguish between tabs and spaces or see where line breaks are. By viewing white space these special characters can be seen.

Word Wrap

This wraps text to fit within the horizontal limits of the editor eliminating the need to use horizontal scrolling. Lines that wrap are indicated with an arrow on the right hand side of the editor.

Make Uppercase/Make Lowercase

This allows you to change the current selection to all uppercase or all lowercase.

Make Keywords Uppercase/Make Keywords Lowercase

This allows you to create consistent scripts by changing keywords in the current selection to all uppercase or all lowercase.

Go To

If you know the line number you wish to navigate to, you can jump straight to that line by using the Go To dialog. Enter the line number you wish to jump to and click OK.

Snippets, Member Assistance (Premium Edition Only), QuickInfo (Premium Edition Only)

The editor also provides the ability to insert pre-defined customizable blocks of code (see using Snippets for more details), get assistance on database objects (see getting Member Assistance for more details), and get informative tool tips on database objects (see getting QuickInfo for more details).

Changing connection

If you wish to change the database you are connected to double click on the status bar over the server or database name. Select the server and database you wish to connect to and click OK.

When the Execution Targets window is open and you are in single database mode then simply click on the name of the database you wish to change connection to.