Visual Query Builder
Top  Previous  Next


Visual Query Builder is a powerful tool, provided for visual building database queries. Using Query Builder you can select tables and fields, join tables, set conditions for the selection and perform many more query operations without knowledge of SQL. Visual Query Builder is based on the EMS QueryBuilder Component (check http://www.ems-hitech.com/querybuilder/ for details).

Building Query  
 
The main area of the Query Builder is the Builder area. Here you can build your query by placing the database tables on the area, selecting the required data and setting links between objects.

Adding a table to the query
To add a table to the query, choose it in the table list at the right, then double-click it or drag it to the Builder area. The selected table will appear on the Builder area with the list of its fields.

Including a table field to the query
To include the table field to the query, click at the left of the field name in the list or double-click it to set the blue icon next to the field name. To include all the fields, set a flag at the left of the table alias. To remove the fields from the query, uncheck the fields; to remove the table, close it by clicking the button '
´' next to the table alias. To edit the table alias, double-click it.

Associating tables by fields
To associate tables by two fields, just drag one field from the table field list to another. This will set a link between these tables by the selected fields. When you drop a field, a line will appear between the linked fields. You can view and edit the properties of object association. To view the properties, just aim cursor to the link line and a hint, containing the association condition, will appear. To edit the properties, double click the line or right-click and choose Properties item from the popup menu. A dialog window will appear, where you can change the association condition by choosing it from the list (=, >, <, >=, <=, <>). Also you can check or uncheck Include all from <table_name> option for each object, included into the association. Click OK to confirm the changes you made. To drop a link between the tables, right-click on the link line and choose Delete Link item from the popup menu. To delete all the links of the table, click button '-' next to the table alias. To insert a point to the link line, right-click on the line and choose Insert Point item from the popup menu. A new point will appear, using which you can move the link line. It doesn't cause any changes in the query but makes the diagram performing more obvious and the visual building handler.

Setting Query Properties  
 
To set other query properties, use tabs at the lower part of the window.

Criterions
In the Criterions area you can set the selection conditions. To add a condition, click button at the left and select Add condition in the popup menu. Edit the condition by clicking its parts and setting their values. Clicking the button at the left of the condition string activates the popup menu, which allows you to add a new condition of the same enclosure level, add a new enclosure level, delete the current condition, open or close the condition, if it is composite. A simple condition string contains three fields: an argument, a condition and a second argument (if required for the condition). Clicking each field allows you to set its value. Clicking the argument field allows editing it as a text field. You can set a table name or a definite value in this field. Right-clicking the field in the edit mode activates the popup menu, which contains the Insert Field function (also called by Shift+Enter). This function allows you to choose a field from the list of all the table fields, available in the query. Clicking the condition field activates the popup menu, where you choose the condition you need. The way of processing the condition is set in the upper string of the area (All, Any, None, or Not all of the following are met). Click the underlined word to change it.

Selection
The Selection area displays the output fields of the query. It allows you to edit the names of the query output fields, set their displaying order and set the aggregate functions (SUM, MIN, MAX, AVG, COUNT) for each field. To remove the field from the list, right-click the field row and choose Delete current row from the popup menu. To change the input query field, double click it and then type the field name on the keyboard or choose it from the drop-down list.
To change the output query field name, double click it and type the field name on the keyboard.
To set the aggregate function for the field, double click the field row in the Aggregate column and then type the function name on the keyboard or choose it from the drop-down list.
If you check option Include only unique records then the repeated records will not be included into the query result.

Grouping Criterions
In the Grouping Criterions area you can set the conditions for grouping the query records. They are set in the same way as the selection conditions (see above). These conditions will be included into the HAVING statement of the current query.

Sorting
Set the way of sorting the query records in the Sorting area. The field list at the left represents all the output query fields; the list at the right contains fields, by which the query records will be sorted. To move the field from one list to another, drag the selected field or use buttons Add and Remove. To change the sorting order, select a field in the right list and move it using buttons Up and Down. To change the sorting direction, select a filed in the right list and switch the direction (Ascending, Descending) using button A..Z/Z..A.

When the query is ready, click button Prepare Query on the toolbar or press Ctrl+F9 to check the query for errors. If there were any errors in building the query text, you will get the appropriate message, describing the error. If everything is correct, you can execute the query by clicking button Execute on the toolbar. This will display the Results area.

Results Tab  
 
This area displays the result data returned by the query. They can be viewed in three modes (chosen by clicking the according button at the bottom of the window):

Grid View
View data as a grid.

Form View
View data as a form: there is only one record displayed at the time, to view another record use the navigation buttons.

Print Data
View data in WYSIWYG mode, ready for printing. The acquired query can be saved to filed and/or printed.

These data can't be edited, but can be exported (Export Data item in the popup menu or button on the toolbar) or exported as INSERT statement to the SQL Script (Export as Insert item in the popup menu or button on the toolbar).

The status bar displays the number of records, acquired while executing the query.

Edit Tab  
 
In the Edit area the query text is automatically generated while you build query. You can edit this text according to the rules of SQL, and all the changes will be displayed on the other pages of the Query Builder.

Query Builder Toolbar  
 

Button
Action


Databases
Drops down with a list of registered databases, allowing you to select the database for the query.
Load
Loads the query text from an *.sql file.
Save
Saves the query text to an *.sql file.
Delete Current Query
Clears the current query.
Help on SQL
Calls the PostgreSQL Help window.
Execute
Executes the query.
Prepare Query
Checks the query text for errors and compiles the query plan.
Commit Transaction
Commits the current transaction.
Rollback Transaction
Rollbacks the current transaction.
Export Data (Results tab only)
Activates the Export Data Dialog, which allows you to export the result query data to file.
Export Data as INSERT Statements (Results tab only)
Activates the Export Data As Insert Dialog, which allows you to export the result query data to the SQL script as INSERT statements.
View

Allows you to show/hide the table list at the right of the window.
Default Size and Position
Brings the window to its default size and position (restricted by the main window and DB Explorer).


See also:
SQL Editor
SQL Script Editor
SQL Monitor


Availability:
Windows Professional

Yes

Windows Lite

No

Linux Professional

No

Linux Lite

No