query builder overview

13
Using the Query Builder in Toad for Data Analysis written by Shawn Pickett, Senior Developer and Alan Bala, Development Team Lead, Quest Software, Inc

Upload: 44452555

Post on 28-Oct-2014

24 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Query Builder Overview

Using the Query Builder in Toad for Data Analysis

written by Shawn Pickett, Senior Developer

and Alan Bala, Development Team Lead,

Quest Software, Inc

Page 2: Query Builder Overview

Query Builder – Overview

Page 2 of 13

Table of Contents

QUERY BUILDER OVERVIEW ................................................................................... 3

THE QUERY BUILDER CONTROL ................................................................................................. 3 SAVING FILES .............................................................................................................................. 4 DEFAULT SETTINGS ..................................................................................................................... 4

WORKING WITH THE QUERY BUILDER ............................................................... 5

USING BIND VARIABLES ............................................................................................................. 5 FORMULAS .................................................................................................................................. 6 SUBQUERIES ................................................................................................................................ 6 DISTINCT VALUES ....................................................................................................................... 7 DATE RANGES ............................................................................................................................. 7 LOOKUP TABLES ......................................................................................................................... 8

HETEROGENEOUS QUERIES ..................................................................................... 9

QUERY LIMITATIONS................................................................................................................. 10

REVERSE ENGINEERING .......................................................................................... 10

REVERSE ENGINEERING LIMITATIONS ...................................................................................... 12

ABOUT QUEST SOFTWARE, INC. ........................................................................... 13

CONTACTING QUEST SOFTWARE .............................................................................................. 13 CONTACTING QUEST SUPPORT.................................................................................................. 13

Page 3: Query Builder Overview

Query Builder – Overview

Page 3 of 13

Query Builder Overview

This document offers guidelines and guidance to help you use the Toad for Data Analysts

Query Builder.

The Query Builder is an efficient and easy way to visually create SQL queries. Tables

and views can be added either by dragging and dropping the object to the pane or by

right-clicking on the selected object and selecting the Send To menu option: Send To

Query Builder. In Toad for Data Analysts, you can also access the Query Builder by

clicking on the Query tab on the Wizard bar.

The Query Builder Control

A Flash Demo of the Query Builder can be viewed here:

http://toadworld.com/Portals/0/assets_ifs/flashdemos/TDA-QueryBuilder/index.htm

Page 4: Query Builder Overview

Query Builder – Overview

Page 4 of 13

Saving Files

Query Builder files are saved and can be identified with the *.tsm file extension. This

xml format file contains all the information needed to restore the saved state including all

the objects, joins, where conditions, positioning etc… of the Query Builder control. The

file save menu can be found by right-clicking on the Query Builder document tab or from

the main menu under File Save File when a Query Builder document tab is selected.

Default Settings

The Query Builder options are accessible from the main menu under Tools Options

Database Query Builder and from main menu under Query Builder Query Builder

Settings when the Query Builder is open. From here you can choose to fully qualify

object and column names and limit the number of objects added to the control.

Checking Use fully qualified object names will fully qualify the object name with

schema in the form of schema.table.

Checking Use fully qualified column names will fully qualify the column name in

the form of table.column,

The default of limiting the maximum number of objects to 50 was selected to limit

impact on the database and for optimal application responsiveness.

Page 5: Query Builder Overview

Query Builder – Overview

Page 5 of 13

Working with the Query Builder

Using Bind Variables The use of bind variables is supported when you specify the query criteria in the Query

Builder. At runtime, you will be asked to provide values for the variables before the

statement can be executed.

Page 6: Query Builder Overview

Query Builder – Overview

Page 6 of 13

Formulas Formulas can be applied to columns and calculated fields. Choose from the pre-defined

list of functions and operators or free text the formula directly.

Subqueries

The query build allows you to add a sub query to the FROM clause. A sub query can be

added by clicking on the Add Subquery toolbar button or from the context menu on the

diagramming surface. Activating this option opens the Queries tree on the left side of the

form and opens a sub query builder control. You add tables and views and create joins in

the same way as you normally use the query builder.

When you are done creating the sub query, click the parent query in the Queries tree to go

back to the original query. The first thing you will notice is a new table on the diagram

surface with all the columns from the sub query. Use this new table as you would any

other database object. You can nest sub queries and the Where Condition sub query

works as it did before.

.

Page 7: Query Builder Overview

Query Builder – Overview

Page 7 of 13

Distinct Values

Date Ranges

When you open the Where Condition dialog for a column that has a Date data type, you

will notice a new tab named Date Range. The Date Range tab allows you to select a plain

text tag such as, “Today,” “Last week,” “Last 30 days,” and “Current year.” The tag you

select is added to the where clause of your query and when executed it is substituted with

a BETWEEN command using the appropriate date range. Date Range tags can also be

used in the SQL Editor so you can create queries manually if you wish.

Page 8: Query Builder Overview

Query Builder – Overview

Page 8 of 13

Lookup Tables A lookup table is an associative array which in the context of a database application

creates a new table with defined relationships to the distinct values of the original table.

Page 9: Query Builder Overview

Query Builder – Overview

Page 9 of 13

Heterogeneous Queries

You can use the query builder to add tables and views from multiple databases and

retrieve a combined result set. With a query builder open, you can change connections

and still add tables from a different database. Once a table or view from a different

database has been added to the query builder, a watermark is shown indicating you are

working with a heterogeneous query.

Note: The Query Builder uses the Microsoft Access database installed with Toad as a

staging area for the query. You should not uninstall this database if you intend to create

heterogeneous queries.

The query engine uses an ODBC connection to connect to the database where the table

resides even when connected via one of the .Net native providers.

Page 10: Query Builder Overview

Query Builder – Overview

Page 10 of 13

Query Limitations

Executing a heterogeneous query may take longer than a query run against a single

database. ODBC data retrieval is naturally slowing than using a native database client

connection. In addition, result sets from each database are retrieved and combined

increasing the length of time to get a result set.

Sub queries do not work with heterogeneous queries so all access points to add sub

queries have been disabled. The only join types that work with heterogeneous queries are

CROSS JOIN and INNER JOIN. All access points to change the join type have been

disabled.

You cannot create a heterogeneous query from a DB2 native client connection. You must

first establish an ODBC connection to the DB2 database and then create the query.

You cannot create a heterogeneous query between two or more Excel connections.

Heterogeneous queries between Microsoft Access and Microsoft Excel are not supported.

Result sets from a heterogeneous query cannot be edited.

Reverse Engineering The Query Builder allows you to enter a SELECT statement in the Query tab and reverse

engineer it into a visual representation on the Diagram tab.

Simply type or paste a SELECT statement into the editor on the Query tab and click on

the Visualize SQL statement button to draw a diagram of the objects and relations in the

SQL. The statement can contain calculated columns, WHERE, HAVING, GROUP BY,

ORDER BY clauses, and sub SELECT statements. Edits made on the Diagram tab will

cause the Query tab to be updated thus overwriting the entered SQL.

Page 11: Query Builder Overview

Query Builder – Overview

Page 11 of 13

Since a WHERE or HAVING clause can be entered that the Query Builder can not

visually represent, the Global Clause objects are used to contain the logic of the clause.

Reverse engineering a SELECT statement that contains a WHERE or HAVING clause

produces a Global Where Clause or Global Having Clause object in the Diagram. The

Global Clause can be edited by double clicking on the object or clicking the Global

Where or Global Having buttons on the toolbar.

Errors in the SELECT statement will be flagged in the editor and added to the Output

window.

Page 12: Query Builder Overview

Query Builder – Overview

Page 12 of 13

Reverse Engineering Limitations

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.

UNION, MINUS and EXCLUDE joins are not supported. You can build the statement in

the Query Builder and send it to the editor to add one of these join types.

You cannot reverse engineer heterogeneous queries.

If you are connected via ODBC, you must use ANSI SQL for the query.

Page 13: Query Builder Overview

Query Builder – Overview

Page 13 of 13

ABOUT QUEST SOFTWARE, INC. Quest Software, Inc., a leading enterprise systems management vendor, delivers

innovative products that help organizations get more performance and productivity from

their applications, databases, Windows infrastructure and virtual environments. Through

a deep expertise in IT operations and a continued focus on what works best, Quest helps

more than 90,000 customers worldwide meet higher expectations for enterprise IT.

Quest’s Foglight® application management solution unifies IT services with end users

and the business, resolves problems faster to reduce downtime, and lowers the operating

cost of managing applications. Quest Software can be found in offices around the globe

and at www.quest.com.

Contacting Quest Software Phone: 949.754.8000 (United States and Canada)

Email: [email protected]

Mail: Quest Software, Inc.

World Headquarters

5 Polaris Way

Aliso Viejo, CA 92656

USA

Web site: www.quest.com Please refer to our Web site for regional and international

office information.

Contacting Quest Support Quest Support is available to customers who have a trial version of a Quest product or

who have purchased a commercial version and have a valid maintenance contract. Quest

Support provides around the clock coverage with SupportLink, our web self-service.

Visit SupportLink at http://support.quest.com From SupportLink, you can do the

following:

Quickly find thousands of solutions (Knowledgebase articles/documents).

Download patches and upgrades.

Seek help from a Support engineer.

Log and update your case, and check its status.

View the Global Support Guide for a detailed explanation of support programs, online

services, contact information, and policy and procedures. The guide is available at:

http://support.quest.com/pdfs/Global Support Guide.pdf