One way to build a query is to begin adding columns and creating joins in the Query Builder, and then send the query to the editor to add more complex functionality, such as a UNION join. You can also send a query from the editor to the Query Builder. For example, you inherited a large query when an employee left and you need to edit it to resolve an issue. After looking at the query in the editor for some time, you still cannot decipher it. So, you right-click the statement and select Send to Query Builder. Now that you can visually see how the tables are referenced, you can identify and resolve the issue.
Consider the following when reverse engineering a query using the Query Builder:
General |
Description |
Single statement support |
The Query Builder only supports one statement at a time. If you add multiple statements to the Query tab, only the first statement is used. If you make any changes to the statement on the Diagram tab, the other statements are lost. |
Quote identifiers |
If you selected the Quote Identifiers checkbox in Tools | Options | Database | General and generate a query from the Query Builder in SQL Server, the query cannot be reverse engineered. |
ODBC support |
You must use ANSI SQL for the query. |
Excel support |
Copying a generated query and attempting to reverse engineer that query results in an error. This issue occurs because the parser defaults to Oracle syntax, which does not understand quotation marks for fully qualified object names. To avoid this issue, clear the Use fully qualified object names and Use fully qualified column names checkboxes in Tools | Options | Database | Query Builder or manually edit the query. |
Non-ANSI joins (Oracle only) |
When sending a query from the Editor to the Query Builder, Toad automatically uses ANSI joins. If you use Where clause joins, click to disable ANSI joins. This converts the statement to the correct join. |
Where Condition |
Description |
Where condition does not display in the Criteria grid after sending it to the Query Builder from the Editor |
If you send a query that contains a Where condition from the editor to the Query Builder, it displays in a Global Where clause bubble on the Diagram pane instead of in the Where Condition field in the Criteria grid. You can double-click the Global Where Clause bubble in the Diagram pane or can click to edit it. You can also use the Where condition fields in the Criteria grid to add new Where conditions. Although they display in the grid, they are added to the Global Where clause in the Query tab. |
Where condition created in the Criteria grid of the Diagram tab disappears |
If you define a Where condition in the Criteria grid and edit any part of the query in the Query tab, the Where condition is removed from the Criteria grid and placed in a Global Where Clause bubble. You can double-click the Global Where Clause bubble in the Diagram pane or can click to edit it. |
Having Condition |
Description |
Having condition does not display in the Criteria grid after sending it to the Query Builder from the Editor |
If you send a query that contains a Having condition from the editor to the Query Builder, it displays in a Global Having clause bubble on the Diagram pane instead of in the Having Condition field in the Criteria grid. You can double-click the Global Having Clause bubble in the Diagram pane or can click to edit it. You can also use the Having condition fields in the Criteria grid to add new Having conditions. Although they display in the grid, they are added to the Global Where clause in the Query tab. |
Having condition created in the Criteria grid of the Diagram tab disappears |
If you define a Having condition in the Criteria grid and edit any part of the query in the Query tab, the Having condition is removed from the Criteria grid and placed in a Global Having Clause bubble. You can double-click the Global Having Clause bubble in the Diagram pane or can click to edit it. |
Query Builder Diagram Tab |
Description |
Comments and code regions removed after making changes in the Diagram tab |
When reverse engineering a statement from the editor or the Query tab and switching to the Diagram tab, if the statement contains a block comment or code region and you make a change in the Diagram tab, the comment or code region is removed from the statement. |
Same column cannot be used in the criteria grid |
You cannot use the same column more than once in the criteria grid. Even if you create a separate alias for the second use of the column, that column is created as a calculated field |
Execute with different query in the Diagram and Query tabs |
If the query in the Diagram tab is different than the query in the Query tab, executing the query executes the SQL in the Query tab instead of the Diagram. |
Save with different query in the Diagram and Query tabs |
The Query Builder saves both the statement and diagram in the same file. The contents of the statement and diagram can be different without losing changes. |
To reverse engineer a query
Right-click a statement in the Editor, and select Send to Query Builder.See About Editing SQL for more information.
or
Click in the Query Builder to send a statement to the Editor. Skip the remaining steps and continue to edit the query. See About Editing SQL for more information.
Troubleshooting: If the query cannot be modeled in the Diagram tab, a message displays and the statement opens in the Query tab. This usually occurs because the graphical diagram cannot support some functionality in the statement. You can view an explanation for this in the Output window or by hovering over the syntax with a red underline () in the Query tab. To continue, correct the error and click to apply the change and open the Diagram tab.
Continue to build your query visually using the diagram.
Select the Query tab and make any additional edits. Indicators for an edited statement are as follows:
|
Inserted lines |
|
Modified or removed lines |
|
Modified characters |
Use the toolbar in the lower-right corner of the Query tab to modify the color used for each indicator. |
Caution: If you manually enter or update the statement in the Query tab, you must click to model the query in the Diagram tab. If you do not do this and make additional changes in the Diagram tab, any changes you made in the Query tab are lost.
Click to execute the query.
Tip: If you have multiple statements in the Editor and you want to send only one to the Query Builder, highlight the statement, then right-click it and select Send to Query Builder.
Create Cross-Connection Queries
In this tutorial you will create a subquery to use to filter your selection of address IDs to only those addresses from specific regions.
To build a subquery
Connect to the Toad Sample (Access) database in the Navigation Manager.
Click these column names in the ADDRESS table to add the columns to the query:
Select the Where field in the REGION_ID column and click . The Where Condition editor displays.
Select the IN operator from the list, and then click Subquery.
A child Query Builder window displays for you to use to build the subquery.
The child (subquery) Query Builder window includes a Diagram pane, a Criteria pane, and a Queries pane for navigating back and forth between subqueries and the main query.
Drag the REGION table to the Diagram pane and select the REGION_ID column.
Select the Where field in the REGION_ID column and click . In the Where Condition editor, select the In comparison operator, select Constant, and select the values 1 and 2.
Your subquery window should look something like this:
Click the Query node in the Queries pane to return to the main query window. A call-out in the main query Diagram pane indicates that the statement contains a subquery and identifies the column it is on. Hover over the call-out to view the subquery statement.
The editor combines a powerful SQL and procedure editor into a single interface.
Notes:
To edit SQL
Select Tools | Edit
Note: You can query the worksheet from the Editor by entering a dollar sign ($) followed by a cell range to limit the results similar to the following statement:
Select * from (MyWorksheet$A1:C10)
You can also query the entire worksheet by entering a dollar sign ($) after the worksheet name; however, this returns empty rows and columns in the worksheet.
Review the following to help enter SQL:
Click to format the code.
Select the block of code in the Editor, and click to validate the syntax.
Note: Toad undoes any changes to the object and data in the database after executing the script (notice that the Result Sets tab is empty). To modify the object and data, you need to execute the script.
Click to execute SQL on the current server or multiple servers at one time.
You can specify options for the look and behavior of the SQL Editor by using the Toad Options dialog.
To configure Editor options
To specify one of the following options, select the corresponding page in the Options dialog.
Option Description |
Page in Options Dialog |
---|---|
Display the tabs for the current connection only when using Tabbed windows |
Select Environment | Interface |
Change background color of the Editor | Select Editor | General |
Use connection color as background color | Select Editor | General |
Position Editor tab headers vertically | Select Environment | Interface |
Set options to display line numbers, line modifications, and general text formatting |
Select Editor | General |
Specify options to automatically replace typed text with the correct substitution text |
Select Editor | Auto-replace |
Customize code formatting options including headers and layout characteristics |
Select Editor | Formatter |
Click here to view a video of this feature.
You can assign individual shortcut keys in Keyboard options.
Caution! If you have some global access keys assigned, make sure that Toad shortcut keys do not coincide with them. When using such duplicating shortcut keys in Toad, the third party application commands, assigned globally, will be performed instead of ones assigned by Toad.
Tip: You can also use Auto-replace to specify words which can be used as shortcuts for entering phrases or statements. See Use Auto-Replace in the Editor for more information.
The following table describes the default shortcut keys in Toad.
Frequently Used Functions |
Description |
CTRL+PERIOD |
Displays the code completion list |
F9 |
Execute current statement |
F5 |
Execute all statements, in order, one at a time |
CTRL+MINUS |
Comments the selected line |
CTRL+SHIFT+MINUS |
Uncomments the selected line |
CTRL+J |
Collapses all code regions |
CTRL+M |
Expands all code regions |
ALT+PAUSE |
Stops script execution |
Bookmark |
Description |
CTRL+SHIFT+0-9 |
Sets a numbered bookmark at the selected line |
CTRL+0-9 |
Goes to the numbered bookmark |
Case |
Description |
CTRL+L |
Converts the selected text to lowercase |
CTRL+U |
Converts the selected text to uppercase |
Clipboard |
Description |
CTRL+C |
Copies the selected text to the clipboard |
CTRL+X |
Cuts the selected text for pasting in the clipboard |
CTRL+V |
Pastes text from the clipboard |
Code Completion |
Description |
CTRL+PERIOD |
Displays code completion list |
ENTER |
Selects an item and close the code completion list |
CTRL+SPACE |
Selects an item without closing the code completion list |
CTRL+<right arrow> |
Expands a node in the code completion list |
CTRL+<left arrow> |
Collapses a node in the code completion list |
Comment |
Description |
CTRL+MINUS |
Comments the selected line |
CTRL+SHIFT+MINUS |
Uncomments the selected line |
Cursor |
Description |
HOME |
Moves the cursor to the beginning of the line |
CTRL+HOME |
Moves the cursor to the beginning of the file |
END |
Moves the cursor to the end of the line |
CTRL+END |
Moves the cursor to the end of the file |
Debugger |
Description |
SHIFT+F12 |
Step from cursor |
F7 |
Step into |
SHIFT+F7 |
Step out |
F8 |
Step over |
F11 |
Run to breakpoint |
F12 |
Run to cursor |
CTRL+B |
Set breakpoint |
CTRL+W |
Add watch at cursor |
Delete |
Description |
BACKSPACE |
Deletes the selected text (if text is selected); otherwise, deletes the previous character |
CTRL+BACKSPACE |
Deletes text to the beginning of the previous word |
CTRL+SHIFT+DELETE |
Deletes the entire script |
Find and Replace |
Description |
CTRL+F |
Finds text |
F3 |
Finds the next occurrence of text |
SHIFT+F3 |
Finds the previous occurrence of text |
CTRL+G |
Goes to line number |
CTRL+I |
Performs an incremental search |
CTRL+SHIFT+I |
Performs a reverse incremental search |
Indent |
Description |
TAB |
Indents the selected line |
SHIFT+TAB |
Outdents the selected line |
Macros |
Description |
CTRL+SHIFT+R |
Starts/Stops recording a macro |
CTRL+SHIFT+P |
Plays the recorded macro |
Miscellaneous |
Description |
F4 |
Invokes objects search |
F4+SHIFT |
Describes the object next to the cursor |
F6 |
Toggles between the Editor and Data Grid |
CTRL+R |
Show/hide Results pane |
CTRL+D |
Sends SQL to Query Builder |
SHIFT+F8 |
Recalls the previous SQL statement |
CTRL+á |
Scrolls up the window. |
CTRL+â |
Scrolls down the window |
<auto-replace token>+SPACE |
Automatically replaces a misspelled word, inserts symbols, and expands text. Note: You can set autoreplace in Tools | Options | Editor | Autoreplace. |
CTRL+SPACE |
Displays the Code Snippets folder browser |
<code snippet shortcut name>+CTRL+SPACE |
Inserts the code snippet template |
CTRL+DELETE |
Sets the column value for the current cell to Null in the data grid |
© 2024 Quest Software Inc. ALL RIGHTS RESERVED. Nutzungsbedingungen Datenschutz Cookie Preference Center