3.3 Using the Query Window
This section describes how to use the different areas of the MySQL Query Browser query window.
3.3.1 Entering Queries
You can enter queries manually by typing them into the query area, or you can construct queries graphically by using the mouse to select tables, columns, or query components such as joins or WHERE clauses. If you drag multiple tables into a query, MySQL Query Browser constructs a join and tries to determine which columns to use for joining tables. It makes this determination based on foreign key relationships for InnoDB tables, and based on identical column names for other types of tables.
The query currently displayed in the query area can be executed by clicking the Execute button, by entering Ctrl-E at the keyboard, or by selecting a query execution option from the Query menu.
MySQL Query Browser provides syntax highlighting, which helps you see and understand the structure of queries more readily.
Queries are saved in your query history, and you can bookmark specific queries by dragging them to the bookmark browser. Previously executed queries can be recalled by using the bookmark browser or history browser. To use a previous query from one of these browsers, drag it from the browser area to the query area. Recalled queries are subject to further editing.
MySQL Query Browser also helps you create views. To use this feature, execute a SELECT statement and click the Create View button. This brings up a dialog for you to enter the view name. MySQL Query Browser creates a view with the given name, defined using the current SELECT statement. (You can also enter a CREATE VIEW statement directly.)
3.3.2 The Result Area
When you execute a query, its results appear in the query window result area. This area provides flexible result display and has the following characteristics:
- For results that do not fit within the display area, scroll bars appear that allow you to navigate the result by scrolling. It’s also possible to toggle the result set display to use the entire query window.
- If a result set is selected from a single table that has a primary key, the result set can be edited to modify the original table. (There is an Edit button in the result area that enables editing.) You can modify individual values within rows to update them, enter new rows, or delete rows.
- The contents of a result are searchable. The result area has a Search button that provides access to Search and Replace dialogs. You can look for a given value in the entire result or within specific columns. Searches can be case sensitive or not, and they can be based on whole word or partial word matching.
- A result is placed within the current tab of the result area, and each successive query overwrites the tab contents. To prevent this, you can create additional tabs for displaying multiple results and then switch between then.
- You can split a result area tab horizontally or vertically to customize its display or to take advantage of additional features. For example, you can split a tab vertically, load two results into the left and right halves, and then click the Compare button to compare the results. MySQL Query Browser matches up the rows in the two halves to make visual comparison easier. You can also perform master-detail analysis using a split result tab. This type of analysis displays the relationship between master records in one table and the corresponding detail records in another table.
3.3.3 The Script Editor
The query area is designed for entry and execution of single SQL statements. To extend this capability, MySQL Query Browser includes a Script Editor that allows you to edit, execute, and debug scripts that consist of multiple statements.
The Script Editor presents an interface that is displayed as a tab in the result area. To activate it, select either New Script Tab or Open Script ... from the File menu, depending on whether you want to create a new script or edit one that is stored in a file.
The Script Editor offers these features:
- Syntax highlighting
- Line numbering
- Script execution
- Debugging options such as single-stepping and breakpoints
3.3.4 Stored Routine Management
MySQL Query Browser assists you in managing stored procedures several ways:
- It helps you create new routines by prompting for a routine name and taking you to the Script Editor and providing a template for the routine definition.
- You can edit existing routines.
- The database browser shows stored routines in a database when you expand the display for the database. If you expand the display for a routine, the browser shows the routine’s parameters.
3.3.5 The Object and Information Browsers
The right side of the query window contains two browsers: the Object Browser and the Information Browser. The area for each browser contains several sub-browsers.
The area for the Object Browser provides access to databases and queries:
The database browser (schemata browser) displays a hierarchical view of your databases. It lists each database, with the default database name highlighted so that you can tell at a glance which one is current. The default database is the one used for references to tables and routines that are not qualified with a database name.
The display for any database can be expanded to show the tables and stored routines within the database. Likewise, expanding a table display shows its columns and expanding a routine’s display shows its parameters.
Double-clicking a database name selects it as the default database. Double-clicking a table name enters a SELECT * FROM table_name statement in the query area.
Right-clicking in the database browser brings up a menu for additional capabilities:
- Right-click in the browser to create a new database or table.
- Right-click on a database name to drop the database.
- Right-click on a table name to drop the table or edit it with the MySQL Table Editor.
- The bookmark browser lists those queries that you have bookmarked. You can organize bookmarks hierarchically by creating folders and moving, removing, or renaming bookmarks.
- The history browser contains previously issued queries, hierarchically organized by day.
- You can drag queries from the bookmark or history browser to the query area for re-execution. Double-clicking a query also enters it into the query area.
The area for the Information Browser provides access to documentation, query parameters, and current-transaction information:
- The syntax browser lists SQL statements. Double-clicking on a statement displays syntax information for it from the MySQL Reference Manual. The information appears in a tab in the result area.
- The function browser lists the built-in functions that you can use in SQL statements. Double-clicking on a function displays the description for it from the MySQL Reference Manual. The information appears in a tab in the result area.
- The parameter browser displays query parameters.
- The transaction browser shows the statements that are part of the current transaction.