Creating and Editing a Query

This topic explains how to create and edit an SQL query in dbForge Studio.

To create a query:

  1. Create a server connection. For more information about how to create a server connection see Connecting to a Database.
  2. On the Start page, click SQL Development and then click SQL Editor. Alternatively, click New SQL on the Standard toolbar or press CTRL+N. An empty SQL document opens.
  3. Type a query to a database.
  4. Click Execute or press F5 to see the query results.

dbForge Studio SQL editor provides many features that make it easier for you to write and manage your code. Let’s explore some Intellisense features that assist you while coding.

Coding Technique Example:

To show you some dbForge Studio Intellisense features, let us perform a query where we need to display all the employees’ addresses from the AdventureWorks2012 database who are registered in the Newton city.

  1. Open the SQL Editor.
  2. Start typing the select statement. Enter first three letters “sel”. dbForge Studio shows you the list of the relevant keywords and snippets. You can select the SELECT keyword from the list and press ENTER. The keyword appears in the SQL editor.

    Select Statement

    You can also use the select statement fragment. Enter the ‘ssf’ letters, and then press the TAB button. In this case the SELECT * FROM statement appears in the SQL editor.


  3. Specify the table you want to retrieve data from. Start typing the first letters of the table name, and dbForge Studio shows you a list of valid tables from the AdventureWorks2012 database. If you continue typing characters, the list is filtered to include only the tables that begin with those characters. After selecting an item, you can insert it into your code by pressing TAB or ENTER. dbForge Studio also shows a quick info for every highlighted item in the list. It allows you to see the object structure immediately.

    Address Properties

    The Address table comes the first in the list, so choose it and press TAB or ENTER to insert it into the SQL editor. dbForge Studio assigns the alias for the Address table automatically.

  4. We need to select address categories that are stored in separate tables. In a similar way, either type or insert the JOIN keyword and press the SPACE key. dbForge Studio shows you all available solutions to implement JOIN. Select a required statement and press ENTER.

    Join Statement

  5. Use the WHERE statement to finish the query creating where we need to display the addresses from the Newton city only. Type the statement, use the prompt to choose the required item to put under the condition, and press ENTER.

    Where Statement

    Specify the condition where a.City = ‘Newton’.

    Where Statement 2

  6. To format the query text, press CTRL + K, D combination, or choose the Advanced option, on the Edit menu, and click Format Document.

    Formatting Query

  7. To expand the table columns, place the cursor after the asterisk character and press TAB.

    Tab Feature

    There is no need to retrieve all the columns from the Address table, so we can leave only required ones.

  8. Now we can execute the query to see results. To do so, click the Execute button on the Debug toolbar, or press F5.

    Result Set

We got what we wanted.

As you can see, the Intellisense feature provided by dbForge Studio allows you to create complex queries in a few keystrokes.