Other Features
SQL Modeler
The SQL Modeler lets you quickly create the framework of a Select, Insert,
Update, or Delete statement. You can select Tables, Views, or Synonyms, join columns, select columns, and create the desired type of statement.
Ways to invoke the SQL Modeler
• Click the Database | SQL Modeler menu item.
• Click the Open a new SQL Modeler button toolbar.
on the main
The SQL Modeler uses floating list boxes for tables which include check boxes for selecting column(s) and allow for scrollbars and resizing.
The modeler allows for keyboard interaction with the tables. Press the Up Arrow and Down Arrow keys to move up and down, and press the Space Bar to check or uncheck a box.
211
Toad for Oracle
Table Model Area
The Table Model Area lets you graphically lay out a query. You can drag-and-drop tables from the Schema Browser, Project Manager, Object Search window, and Object Palette. The floating list boxes for the tables include check boxes that let you select columns.
To maximize the model viewing area, press F2 or right-click in the model and select Full Screen Model from the right-click menu.
You can visually join or manipulate the Tables, Views, or Synonyms. You can establish your own joins by dragging and dropping a column from one table to another table column. Once the line is drawn, you can double-click the line to adjust its properties, such as Inner Join vs. Outer Join, or Join Test, e.g., equal
(=), less than (<), greater than (>), etc. The selected column information will appear in the Criteria grid below.
Model Area right-click menu
Right-clicking over the model area displays the following menu items.
Copy Model Image to Clipboard
Copies a bitmap image of the model to the Windows Clipboard
212
Other Features
Tables | Visibility
Displays a Tables Visibility window with check boxes next to a list of tables that are in the model. Check/uncheck the individual tables to show/hide them.
Tables | Calculated Fields
Adds calculated fields based on other table columns
Show | Join Text
Displays the column names that comprise the joins
Show | Primary Key
Shows or hides the Table Primary Keys as "(PK)" next to each PK col
Show | Indexes
Shows or hides Indexes as "(IDX)"
Show | Show Field Type
Shows or hides the data type of each table column
SQL | Run Query in Thread
Lets you cancel a query while it is running, if necessary
SQL | Global Where Clauses
Adds a WHERE clause to the query in addition to the column conditions from the
Criteria tab
SQL | Global Having Clauses
Adds a HAVING clause to the query in addition to the columns conditions from the Criteria tab
SQL | Query Variables
Displays the Variables window where you can add and edit variables
Auto Join All Objects
Automatically joins all tables based on existing DDL Foreign Key Constraints
213
Toad for Oracle
Hide Fields
Only shows the table names and the joins between the tables resulting in more layout space
Zoom to table
Automatically shifts the model area so that the table you want to zoom to is in view
Toggle full screen mode
Hides the bottom tabs of the modeler so that the model area is the whole screen allowing you to see more tables.
Auto Trace
Displays results of statements issued while in auto trace mode, helps with tuning.
Close open cursor
Closes the cursor which closes the query and frees resources. Closing the cursor clears the data in the grid.
The right-click menu also includes Optimize All Table Sizes, Adjust Model
Origin, Auto Arrange Tables, Cascade Tables, Arrange Tables
Horizontally, and Arrange Tables Vertically.
Object right-click menu
Right-clicking over a Table object in the model displays the following menu items.
Set Table Alias
Sets the Table alias
Alias Field Names
Sets logical column names
214
Other Features
Auto Join
Automatically joins this table to others based on existing DDL Foreign Key
Constraints
Describe
Performs a describe.
Show Schema Name in SQL
Shows or hides the schema name before each table in the generated query
Include ROWID
Includes the ROWIDs.
Remove Table
Permanently removes this table from the model
Select All
Selects all columns in the table
Unselect All
Unselects all columns in the table
Invert Selection
Selects columns that were unselected and vice versa
Optimize Size
Sets size to the (data) fields listed in the box
Hide
Temporarily hides this table from the model. To unhide the table, right-click over the empty model space and select the Tables | Visibility menu item
215
Toad for Oracle
Results Grid
After you lay out your query, click the Generated Query tab, and the resulting query will display. Other tabs in the window are Criteria, Query Results, and
Explain Plan.
The alias comes from ALIASES.TXT. If the selected table does not have an entry in ALIASES.TXT, the first three characters of the table name are used to generate the alias, which might not always be unique. For example, the aliases for ALL_OBJECTS and ALL_TABLES are both going to be ALL. You can edit the alias as desired to make it unique or change it to something more meaningful.
If the table name is eight characters or less in length, the entire table name is used as the table alias.
The Results Grid contains four tabs: Criteria, Generated Query, Query Results, and Explain Plan.
Criteria tab
If individual columns are selected, they will be displayed in the Criteria grid.
You can edit many of the column properties in the Criteria grid. "Table" and
"Schema" are not editable here. Double-clicking on the following Criteria columns has the following effects:
Double-click on:
• Sort in a column to select Ascending, Descending, or No sort for that column.
• Condition to bring up the Input the WHERE Definition dialog where you can set a column equal to a constant value or another column value. To remove the WHERE definition, bring up the dialog and click the Remove Condition button. To clear the form click the
Clear Form button.
• Or to enter another WHERE criteria, which will be OR'd together with the above WHERE criteria. If you want to AND multiple column criteria together, go to the expert mode from the Input the WHERE
Definition dialog.
216
Other Features
• Aggregate Function to select an aggregate column function such as
Average, Count, Max, Min, Sum, Standard Deviation, or Variance.
• Field Name to enter a different logical column name.
• Visible to toggle whether or not this column is returned in the query
(Show or Not Show).
• Group to select this as a GROUP BY column. A number within parentheses indicates the order of the columns in the GROUP BY clause.
• Group Condition to bring up the "GROUP BY Definition" window to enter a GROUP BY condition.
If you want to change the table alias, right-click over the table in the model and select the Set Alias menu item.
To rearrange the order of the columns, click the column headers and drag and drop them left or right.
Criteria Tab right-click menu
Right-clicking over the Criteria grid will display the following menu items.
Suppress Current Column
Removes this column from the query, which also removes the plus "+" from the column in the model
Best Fit (All Columns)
Sets the column width of the Criteria grid to show all text
Default Width (All Columns)
Sets the column width of the Criteria grid to the default width
Copy Query Grid Image to Clipboard
Copies the Criteria grid to the clipboard. A dialog gives you the options of rotating the image 90 degrees and/or a gray shaded image.
Execute as SQL*Plus Report
Opens the Query Report Format window which lets you format query results in a report style format
217
Toad for Oracle
Generated Query tab
This tab lists the automatically generated SQL statement. Any changes made to the model or column criteria will automatically regenerate this SQL statement.
You can copy the query to the clipboard by selecting it and pressing <CTRL>C or right-clicking and selecting Copy from the popup menu.
You can also copy the query directly to the SQL Edit window by clicking the SQL button in the SQL Modeler toolbar or via the right-click option.
You cannot directly edit the SQL on the Generated Query tab dialog.
The query is syntax highlighted using the same editor settings from the SQL Edit or Stored Procedure Edit window.
218
Other Features
Query Results tab
This grid displays the results of executing the generated query. Insert, Update, and Delete queries can only be executed in the SQL Edit window.
Query Results right-click menu
The Right-click Query Results grid menu includes the following menu items.
Print Grid
Invokes the Print window so that you can print hardcopy of the data. (To access the Report Link Designer click Preview from the Print window and then click the
Design Report button.)
Save As
Invokes the Save Grid Contents window which lets you save data to Clipboard or File.
Export to Flat File
Invokes the Flat File Export from Query window which lets you save the data as a Flat File.
Find Data
Invokes the Grid Data Find window.
Record Count
Displays the number of records in the grid.
The menu also lets you resize columns.
219
Toad for Oracle
Explain Plan tab
If you click the Explain Plan button for a generated SQL statement in the modeler, the Explain Plan output will display on the Explain Plan tab.
Explain Plan tab right-click menu
Right-clicking over the Explain Plan window displays the following menu items.
Copy to Clipboard
Copies the Explain Plan statement (in text mode) to the Clipboard
Optimizer Mode
Lets you select the query optimizer mode for subsequent statements from
Choose, Default, Rule, First Rows, or All Rows
SQL Modeler Options
SQL Modeler options can be set via View | Options | SQL Modeler.
A Modeler Table Text Font drilldown lets you change the font for the table.
A selection list includes Inner Joins, Outer Joins, and Auto Joins.
Click over a color box to select a color for the element. Right-click over the color box to select a background color for the selected item. A preview of the Table object with its new colors displays in the preview window below.
Automatic AutoJoin
Default - Checked
When checked, this feature will automatically check foreign key constraints and join tables that are dropped into a model with other tables. If the option is unchecked, then you can manually join tables with the table popup menu.
Use Schema Name in Generated SQL
Default - Unchecked
If checked, the schema name will be included in the tablename (i.e., myschema.mytable) in the generated SQL. Regardless of whether or not this option is checked, schema names are automatically included if the table belongs to a schema that is different than your login schema.
220
Other Features
Automatically Select All Columns
Default - Unchecked
When checked, all columns are automatically selected when you add a table to the SQL Modeler. If unchecked, no columns are selected.
Allow Cartesian Joins
Default - Unchecked
If checked, the modeler will allow Cartesian products.
Warn on Cartesian Joins
This check box is only enabled if the Allow Cartesian Joins check box is checked.
If checked, you will be prompted each time a Cartesian Join is going to execute.
Default - Unchecked
If checked, when you are in the Schema Browser - Tables page and open a table in the SQL Modeler via either the Tables page | SQL Modeler toolbar button or the Tables page | Model Table right-click item, the Modeler will open in full screen mode. If checked, when you are in the Schema Browser - Views page and open a view in the SQL Modeler via the Views page | Model View right-click item the Modeler will open in full screen mode.
Default - Unchecked/5
This lets you limit the number of visible columns on the table in the model area.
For example, if the spinner is set to 5, the box is checked and you add a table with 10 columns, only 5 columns will display and a scrollbox will let you view the rest of the columns.
Restore All Defaults button
Click this button to discard your customized options and restore the default settings for the options.
221