SQL Assistant
SQL Assistant
SQL Assistant
After completing this appendix, you will be able to:
Define an ODBC data source for Teradata.
Submit SQL using SQL Assistant.
Utilize Explorer Tree to simplify creation of queries.
Use SQL Assistant to import/export a LOB.
SQL Assistant
Page 1
Create reports from any Relational Database that provides an ODBC interface
Export data from the database to a file on a PC
Import data from a PC file directly to the database
Use an import file to create many similar reports (query results or Answer sets).
Send queries to any supported database or the same query to many different databases
Create a historical record of the submitted SQL with timings and status information such
as success or failure
Use the Database Explorer Tree to easily view database objects
Use a procedure builder that gives you a list of valid statements for building the logic of a
stored procedure
Limit data returned to prevent runaway queries
Teradata SQL Assistant also benefits database administrators by allowing them to directly issue
SHOW statements to view text for CREATE or REPLACE commands. The DBA copies the text
to the Query window, uses the Replace function to change a database name, and reissues the
CREATE or REPLACE to define a new object with this new name. You can also display the
CREATE text by going to the shortcut menu of the Database Explorer Tree and clicking Show
Definition.
Page 2
SQL Assistant
Windows-based
Two providers are available for Teradata connections:
Teradata ODBC Driver
Teradata .Net Data Provider
Can be used to access other supported ODBC-compliant databases.
Permits retrieval of previously used queries (History).
Saves information about previous query result sets.
Supports DDL, DML and DCL commands.
Query Builder feature allows for easy creation of SQL statements.
Provides both import and export capabilities to files on a PC.
Provides a Database Explorer Tree to easily view database objects.
Does not support non-ODBC compliant syntax such as:
WITH BY clause
FORMAT clause
SQL Assistant
Page 3
Compatibility
Teradata SQL Assistant is certified to run with any Level 2 compliant 32-bit ODBC driver. The
product also works with Level 1 compliant drivers, but may not provide full functionality.
Consult the ODBC driver documentation to determine the driver's conformance level. Most
commercially available ODBC drivers conform to Level 2.
Note: This module will illustrate the screens defining an ODBC data source. The specific
screens defining a Teradata .Net data source are not provided in this module, but are similar.
Page 4
SQL Assistant
SQL Assistant
Page 5
Use the Connect icon from SQL Assistant and complete the dialog boxes.
In the Define Data Source dialog, decide what type of data source you wish to create:
Data Source Description
Explanation
Page 6
SQL Assistant
SQL Assistant
Page 7
To...
Name
Enter a name that identifies this data source. You can also enter the
name of the system or the logon you will be using.
Description
Name(s) or IP
address(es)
When this option is checked, setup routine does not attempt to resolve
alias names entered into the "Name(s) and IP address(es)" box at setup
time.
Instead it will be resolved at connect time. When unchecked, the setup
routine automatically appends COPn (where n = 1, 2, 3, ..., 128) for each
alias name you enter.
Use Integrated
Security
Mechanism
Select from the list of mechanisms that automatically appear in this box.
Leave this field blank to use the default mechanism.
Parameter
Username
Password
Default Database
Enter the default database you want this logon to use. If the Default
Database is not entered, the Username is used as the default.
Account String
You can optionally enter one of the accounts that assigned to your
Username.
Session Character
Set
Use the drop down menu to choose the character set. The default is
ASCII.
Page 8
SQL Assistant
SQL Assistant
Page 9
Page 10
SQL Assistant
2. Select a
data
source.
SQL Assistant
Page 11
Page 12
SQL Assistant
Default database
is XYZ.
Changes the
default database to
Employee_Sales.
Clicking on SQL
Statement in History
will recall it to the Query
Window later.
SQL Assistant
Page 13
Page 14
SQL Assistant
Main Window
The Query window is where you enter and execute a query. The results from your query are
placed into one or more Answerset windows.
The Answerset window is a table Teradata SQL Assistant uses to display the output of a query.
The History window is a table that displays your past queries and related processing attributes.
The past queries and processing attributes are stored locally in a Microsoft Access database.
This gives you flexibility to work with previous SQL statements in the future.
The Database Explorer Tree displays on the left side of the main Teradata SQL Assistant
window. It displays an alphabetical listing of databases and objects in the connected Teradata
server. You can double-click on a database name to expand the tree display for that database.
You can use the Database Explorer Tree to reduce the time required to build a query and help
reduce errors in object names. The Database Explorer Tree is optional so you can display or hide
this window.
Query
Window
Database
Explorer
Tree
Answerset
Window
History
Window
SQL Assistant
Page 15
Page 16
SQL Assistant
It is not a database hierarchy, but a list of databases and objects that the
user needs to access.
SQL Assistant
Page 17
Page 18
SQL Assistant
Create
query in
Query
Window.
SQL Assistant
Page 19
Page 20
SQL Assistant
Click and drag the object from the Database Explorer tree to the Query window.
The name of the object appears in the Query window.
Options:
If the "Qualify names when dragged or pasted from the Database Tree"
option (Tools > Options) is checked, then the parent name is automatically
included.
Hold Ctrl key causes a comma to be included after the object
Selecting and dragging multiple objects
The Shift and Ctrl keys can also be used to select multiple objects in the
Database Explorer tree for the purpose of dragging multiple objects to the
Query Window.
SQL Assistant
Page 21
Query Options
To submit any part of any query
1.
2.
3.
4.
Formatting a Query
The query formatting feature adds line breaks and indentation before certain keywords, making
SQL that comes from automatic code generators or other sources more readable.
To Format a Query
Note: Some keywords will cause a line break and possibly cause the new line to be indented. If
a keyword is found to already be the first word on a line and it is already prefixed by a tab
character, then its indentation level will not change.
Indentation
When you press the Enter key, the new line will automatically indent to the same level as the
line above.
If you highlight one or more lines in the query and press the Tab key, those lines are indented
one level. If you press Shift-Tab, the highlighted lines are un-indented by one level.
This indentation of lines will only apply if the selected text includes a line feed character. For
example, you must either select at least part of two lines, or if selecting only one line, then the
cursor must be at the beginning of the next line. (Note that this is always the case when you use
the margin to select a line.) If no line end is included in the selected text, or no text is selected,
then a tab character will simply be inserted.
Page 22
SQL Assistant
Highlighted
query in
Query
Window.
SQL Assistant
Page 23
Right-click any column heading to sort the data by that column only. The data is initially
sorted in ascending order. Right-click the same column header again reverses the sort
order.
Note: The output from certain statements (e.g., EXPLAIN) cannot be sorted this way.
To sort an Answerset using a full sort:
Do one of the following: From the Tool Bar, click the sort button, right-click in the
Answerset window and select Sort, or use the Edit > Sort menu.
In the Sort Answerset dialog box, all columns in the active window are presented in the
Available Columns list box.
Select the column name in the Available Columns list box, or use the up or down arrow
keys to highlight the column name and press Enter.
This moves the column name to the Sort keys list box. By default, the sort direction for
this new sort column is ascending (Asc). If you click a column in the Sort Keys list box,
or select the item using the arrow keys or mouse and press Enter, it reverses to
descending sort order (Dsc).
To remove a sort column from the list, double-click the column name, or use the arrow keys to
highlight the column and press Delete.
Page 24
SQL Assistant
The Answerset window is a table that displays the results from a statement.
The output can be sorted in different ways:
Quick sort (single column) right click on the column heading
Full sort (1 or more columns) use Edit > Sort menu or Sort button
Data can be filtered using the funnel option at the column level.
Result set
in
Answerset
Window.
SQL Assistant
Page 25
Formatting Answersets
You can format the colors, font name, font style and font size of a block of cells, individual cells,
rows, columns or the entire spreadsheet. You can also specify the number of decimal places
displayed and if commas are displayed to mark thousand separators in numeric columns.
You can control the Answerset and the Answerset window by setting options. To set Answerset
options, select Tools > Options > Answerset tab.
For example, to display Alternate Answerset Rows in Color, check and first option in the
Answerset tab, and use the Choose button.
Selecting this option makes it easier to see Answerset rows. The option applies the
selected background color to alternating rows in the Answerset grid. The remaining rows
use the standard Window Background color.
The Choose button displays the selected color. Clicking the Choose button allows you to
change this color.
To format the colors, font name, font style and font size of a block of specific cells individual
cells, rows and columns, right-click on the answer set cells. Some options are listed below.
To display commas:
Right-click in the Answerset cell you wish to change and select Format Cells.
Check Display 1000 separators.
Click OK.
Right-click in the Answerset cell you wish to change and select Decimal Places.
Select a number between 0 and 4.
Page 26
SQL Assistant
SQL Assistant
Page 27
Press F2.
Select Help > Query Builder.
Right-click in the Query window and select Query Builder from the shortcut menu.
From the drop-down list in the upper left corner, choose one of the following options.
SQL Statements
Select a command from the statement list in the left pane to display an
example of its syntax in the right pane.
Procedure Builder Select a stored procedure statement from the list in the left pane to display
an example of its syntax in the right pane.
<User Defined>
If you create a custom.syn file, this option appears in the drop-down list.
The name will be the name you specified in the first line of the custom.syn
file. Select this option and the queries you defined in this file will display.
Page 28
SQL Assistant
2. Double-click on
SQL statement
to place sample
query in Query
Window.
SQL Assistant
Page 29
History Window
The History window is a table that displays your past queries and related processing attributes.
The past queries and processing attributes are stored locally in a Microsoft Access 2000
database. This allows the flexibility to work with previous SQL statements in the future.
Clicking any cell in the SQL Statement column in the History window copies the SQL to the
Query Window. It may then be optionally modified and then resubmitted.
You can display or hide the History window at any time.
With Teradata SQL Assistant, all history rows are stored in a single History database. The
History Filter dialog allows you to specify a set of filters to be applied to the history rows. The
operators include >, <, = and LIKE. The filter applies to the entire history table. When you
click in the fields or boxes in the Filter dialog, the possible operators and proper format are
displayed at the bottom of the dialog.
You can filter your history on the following options:
Date
Data source
User Name
Statement Type for example, SELECT or CREATE TABLE
Statement Count show only those queries that contain this many statements
Row Count
Elapsed Time
Show successful queries only
By default, Teradata SQL Assistant records all queries that are submitted. You may change this
option so Teradata SQL Assistant records only those statements that are successful, or turn off
history recording altogether.
The most recently executed statement appears as the first row in the History window. The data
may be sorted locally after it has been loaded into the History window. New entries are added as
the first row of history no matter what sort order has been applied.
Page 30
SQL Assistant
Click on
query in
History
Window.
SQL Assistant
Page 31
General Options
To set general program preferences:
1. Select Tools > Options.
2. Click the General tab.
3. Choose from the following options:
Allow multiple Queries - allows you to have multiple query windows open
simultaneously. With this option selected, the New Query command opens a new tab
in the Query window. The default for this setting is unchecked.
Display this string for Null data fields - enter the string you want displayed in place
of Null data fields in your reports and imported/exported files. The default for this
setting is "?."
General options (Tools > Options > General tab) that are available include:
Page 32
SQL Assistant
Connections
have been made
to two systems:
tdt5-1
tdt6-1
Multiple queries
for tdt5-1 are
shown via tabs.
History includes
the Source name
for queries.
SQL Assistant
Page 33
Additional Options
Teradata SQL Assistant provides many other tools and options, some of which are briefly noted
on the next frame.
Page 34
SQL Assistant
To import and/or export LOB (Large Object) files with SQL Assistant, you need to
first make sure the Use Native Large Object Support option is set with the data
source.
Teradata SQL Assistant supports Large Objects. Large objects come in two types:
Binary these columns may contain Pictures, Music, Word documents, PDF
files, etc.
Text these columns contain text data such as Text, HTML, XML or Rich Text
(RTF).
SQL Assistant > Tools > Options
SQL Assistant
Page 35
Page 36
SQL Assistant
1. Create a data file that contains the name(s) of the LOB(s). This data file
needs to be located in the same folder as the LOB.
TF Manual LOB.txt
1
2
TF Student Manual
TF Lab Workbook
PDF
PDF
SQL Assistant
Page 37
TF_Manual001.pdf
TF_Manual002.pdf
Page 38
SQL Assistant
SQL Assistant
Page 39
Appendix C: Summary
The Teradata SQL Assistant utility can be of great value to you. The next frame summarizes
some of the key features discussed in this appendix.
Page 40
SQL Assistant