Creating and Editing a Query

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

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 Fusion menu, click New SQL

or

2.1. Press CTRL+N. The New File dialog box opens. Use this dialog box to create a new file. Files created using this dialog box are displayed in Solution Explorer under the Miscellaneous Files node.

2.2. On the files categories, select the Devart Files category.

2.3. Select SQL file and then click Open. An empty SQL document opens.

  1. Type a query to a database.

  2. Click Execute or press CTRL+F5 to see the query results.

Coding Technique Example

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

To show you some Fusion for SQL Server 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 SQL Editor.

  2. Start typing a SELECT statement. Enter first three letters “sel”. Fusion for SQL Server 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.

    Intellisense feature

    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.

    SELECT * FROM statement

  3. Specify the table you want to retrieve data from. Start typing the first letters of the table name, and Fusion for SQL Server 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. Fusion for SQL Server 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. Fusion for SQL Server assigns the alias for the Address table automatically.

  4. We need to select address categories stored in separate tables. In a similar way, either type or insert the JOIN keyword and press the SPACE key. Fusion for SQL Server shows you all available solutions to implement JOIN.

    Select a required statement and press ENTER.

    JOIN statement

  5. Use the WHERE clause 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 clause

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

    WHERE clause condition

  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 document

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

    Use the TAB feature to expand columns

    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 this, click the Execute button on the Debug toolbar, or press F5.

Here is the result.

Result set

As you can see, Intellisense feature provided by Fusion for SQL Server allows you to create complex queries in a few keystrokes.