Menü Schließen
Kategorien anzeigen

Abfrage-Tool

Menu path: Tools > Query Tool

The Query Tool offers a quick and direct way to look at the data in the database, and to change it. It overrides all checks on data, so it should be handled with care. The Query Tool is for administrators and is shown at the expert experience level.

If you are not familiar with SQL, you would be better off not using the Query Tool as you might make unwanted changes. You will also need to familiarise yourself with the syntax of HSQL DB.

When Data Crow is connected to a server the Query Tool is available as well, but it is read only: see Client-server.

The window #

On the left is the Database schema and, on a tab next to it, the Saved SQL statements. On the right you enter the query and see its result. The toolbar above the query has the buttons to run, stop, clear, save, format and export (see The buttons).

Database schema #

The schema shows all tables of the database, each with its columns, the data type, the primary key and the references to other tables. The tables and columns of the modules and fields you created yourself show the name of the module and of the field, so you can recognize them. Point at a table or a column to see this information in a tooltip.

Tables of which the name starts with X_ (such as X_SOFTWARE_CATEGORIES) are link tables. They connect the items of a module to the items of a field which can hold several references, such as the categories of a software item. The tooltip of a table shows the module it belongs to.

Die Filter field at the top finds a table or a column on the name of the table or column, or on the name of the module or field. Double-click on a name (or select it and press Enter) to place it in the query.

Erstellen und Ausführen einer SQL-Anweisung #

Enter a SQL statement in the query input and press Run to execute it. The SQL is shown with syntax highlighting: keywords, strings, numbers and comments each have their own colour. Errors are shown if the query was incorrect (these messages are not generated by Data Crow but by the database engine).

  • Suggestions. Presse Ctrl+Space while typing for suggestions of the names of tables and columns (and of SQL keywords). After a table name or an alias (such as m. für MOVIE m) the columns of that table are suggested.
  • A part of the query. When you select a part of the text, only the selection is executed instead of the whole query.
  • Formatting. Format places the main parts of the query (SELECT, FROM, WHERE and so on) on their own lines and aligns them. It formats the selected text, or the whole query when nothing is selected. You can also right-click in the query and choose Format, or press Ctrl+Shift+F.

A query is executed in the background: the window stays usable while it runs and the status line says so. Press Stop to stop it. Closing the window stops a running query as well.

The result #

The result of a select query is shown in the result table. A query shows at most 1000 rows; the status line tells the number of rows and the time it took, and says when there are more rows than the ones shown. Point at the header of a column to see its name and, on the second line, the label of its field (such as the name you gave to a field you created yourself).

The buttons #

The buttons are above the query:

  • Run: runs the SQL query as entered in the query input (or the selected text).
  • Stop: stops the query which is running.
  • Clear: clears all data from the screen.
  • Speichern Sie: saves the query under a name (see Saved SQL statements).
  • Format: formats the query (Ctrl+Shift+F).
  • Examples: example queries for the table or the column which is selected in the database schema. Select a table or a column first.
  • Export CSV: exports the rows shown in the result to a CSV file. Data Crow asks before it replaces a file which exists already.

Example queries #

Die Examples button shows queries which are made for the table or the column you selected in the schema. For a table, for example: the first 100 rows, the number of rows of the table (or of all tables), and all rows with the items they refer to (an inner or an outer join), also with the labels of the fields as names. For a column: the number of rows per value, the values which occur more than once and the rows without a value. A chosen example is placed in the query input; it is not executed until you press Run.

Saved SQL statements #

The tab Saved SQL statements has two groups:

  • Saved: the queries to which you gave a name with the Speichern Sie button. Data Crow asks for the name, and asks whether to replace a query which has the same name.
  • Recently executed: the queries you executed lately (the last 50, the latest first). The same query is only kept once.

Double-click on a query (or select it and press Enter) to place it in the query input. A right-click gives the options Load und Löschen; the Delete key deletes the selected query as well, after a confirmation. Point at a query to see its SQL.

Changing data #

In a stand-alone installation you can change data too. A statement which changes data is not final right away: Data Crow shows how many rows were affected and asks whether to commit the changes or to roll them back (the default). A change or a delete without a WHERE clause gets an extra warning, as it applies to all rows of the table.

A statement which changes the structure or the settings of the database cannot be rolled back. Data Crow asks for confirmation before it executes such a statement. Make a backup first when you are not sure.

Client-server #

When Data Crow is connected to a server, administrators can use the Query Tool as well. It is then read only: the server only executes queries (SELECT), one statement at a time. Changes to the data have to be made in stand-alone mode. A query which takes more than 20 seconds is stopped by the server, and when too many queries are running at the same time you have to wait until one has finished.