Creating and Editing a Query

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

To create a query:

  1. Create a server connection.
  2. On the Fusion menu click, click New SQL. Alternatively, click the Create New SQL button on the Devart - Main toolbar. A new SQL document opens.
  3. Start type a query to a database.
  4. Click Execute on the Devart - SQL toolbar to see the query results.

Coding Techniques Example

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

For an example, let’s use the HR database and perform a sample query where we display all the employees working in the Shipping department, department ID is set to 50.

  1. Open the SQL Editor.
  2. Start typing the SELECT statement. Enter first three letters “sel”. dbForge Fusion 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.
    You can also select the “sel” snippet from the list and press the TAB button. In this case the SELECT * FROM statement appears in the SQL editor.

    sel statement

    If you start type the same letters “sel” a little faster, before the list appears (by default the list has 200 ms delay), a little tool tip appears next to the letters. It signals that you can press the TAB button to complete the statement automatically by inserting a snippet.

    TAB feature

    Regardless of the method you choose, the SQL editor displays the SELECT * FROM statement.

  3. Now, lets type a table name from which we want to retrieve the data. Start type “e”. dbForge Fusion shows you a list of valid members from the HR database. If you continue typing characters, the list is filtered to include only the members that begin with those characters. After selecting an item, you can insert it into your code by pressing TAB or ENTER. dbForge Fusion also shows a quick info for every highlighted item in the list. It allows you to see the object structure immediately.

    Tip_1

    The EMPLOYEES table comes the third on the list, so choose it and press TAB or ENTER to insert it into the SQL editor. dbForge Fusion assigns the alias for the EMPLOYEES table automatically.

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

    Tip_2

  5. The last step in creating a query is to add the condition. Add the AND E. DEPARTMENT_ID = 50 statement at the end of the query.
  6. To format the query text, right-click anywhere in the document window, and select Format Document from the shortcut menu. Now we can execute the query to see results. To do so, click the Execute button on the Debug toolbar, or press F5.
  7. Place the cursor after the asterisk character and press TAB.

    Format Document

    dbForge Fusion shows the columns list that are available in the EMPLOYEES table.

    Star Feature

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

    Star Feature

  9. The last step is to press F5 to execute the query.

    Results

We got what we wanted.

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