0% found this document useful (0 votes)
455 views

SQL Assistant

This doc will describe how to use teradata SQL assistant tool

Uploaded by

prince jain
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
455 views

SQL Assistant

This doc will describe how to use teradata SQL assistant tool

Uploaded by

prince jain
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 40

Appendix

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.

Teradata Corporation Copyright 20072015. All Rights Reserved.

SQL Assistant

Page 1

SQL Assistant Features


Teradata SQL Assistant is an information discovery tool designed for Windows XP and
Windows 2000. Teradata SQL Assistant retrieves data from any ODBC-compliant database
server. The data can then be manipulated and stored on the desktop PC.
Teradata SQL Assistant is a query tool written for relational database developers. It is intended
for SQL-proficient developers who know how to formulate queries for processing on Teradata or
other ODBC-compliant Databases. Used as a discovery tool, Teradata SQL Assistant catalogs
submitted instructions to arrive at a derived answer. Teradata SQL Assistant stores the history of
your SQL in a local Microsoft Access database table. This history is available in future
executions of Teradata SQL Assistant.
Teradata SQL Assistant accepts standard Teradata SQL, DDL and DML. In addition, Teradata
SQL Assistant sends native SQL to any other database that provides an ODBC driver. If the
driver supports the statements, they are processed correctly.
Key features of SQL Assistant include:

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

SQL Assistant is a Windows-based utility for submitting SQL to Teradata.


SQL Assistant has the following properties:

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

Defining a Data Source


Before using Teradata SQL Assistant to access the Teradata database, you must first install the
Teradata ODBC driver on your PC and the .Net Data Provider for Teradata. When connecting to
a Teradata database, you can use either ODBC or the .Net Data Provider for Teradata.
Connection to any other database must be made through an ODBC connection. In order to use
the ODBC connection, a vendor specific ODBC driver must be installed.
Before you can use Teradata SQL Assistant, you will need to define a data source, namely the
instance of the database you wish to work with.

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.

Defining a Teradata .Net data source


Use the Connection Information dialog to create, edit and delete data sources for .Net for
Teradata. This dialog box is also used to connect to a .Net data source.
To define a Teradata .Net data source
1.
2.
3.
4.
5.

Open Teradata SQL Assistant.


Select Teradata .Net from the provider drop down list.
Click the Connect icon or go to Tools > Connect.
Use the Connection Information dialog to choose a .Net data source.
Create a new data source by entering the name and server and other applicable
information

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

You can define an ODBC data source in these ways:

SQL Assistant (select Connect icon)


Select Tools > Define ODBC Data Source
ODBC Data Source Administrator Program
SQL Assistant 13.10 has two
provider options:
Teradata .Net Data Provider
ODBC

Select the Machine Data


Source tab and click on New
to create a new data source.

SQL Assistant

Page 5

Defining a Data Source (continued)


When connecting to the Teradata database, use either the ODBC or the Teradata .Net Data
Provider. Connection to any other database must be made through an ODBC connection.

Defining an ODBC Data Source


An ODBC-based application like Teradata SQL Assistant accesses the data in a database through
an ODBC data source.
After installing Teradata SQL Assistant on a workstation or PC, start Teradata SQL Assistant.
Next, define a data source for each database.
The Microsoft ODBC Data Source Administrator maintains ODBC data sources and drivers and
can be used to add, modify, or remove ODBC drivers and configure data sources. An
About Box for each installed ODBC driver provides author, version number, module size, and
release date.
To define an ODBC data source, do one of the following:

From the Windows desktop, select


Start > Control Panel > Administrative Tools > Data Sources (ODBC)

From the Windows desktop, select


Start > Programs > Teradata SQL Assistant
After SQL Assistant launches, select Tools > Define Data Source

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

A User Data Source can be


used only by the current
Windows user

An ODBC user data source stores information about how to


connect to the indicated data provider. A user data source is only
visible to you.

A System Data Source can


be used by any user defined
on your PC.

An ODBC system data source stores information about how to


connect to the indicated data provider. A system data source is
visible to all users on this machine, including NT services.

Page 6

SQL Assistant

Select the System Data Source


and click Next to create a new data
source.

Select Teradata as the


driver and click Finish on
the confirmation screen.

SQL Assistant

Page 7

Defining a Data Source (continued)


A dialog box (specific to Teradata) is used to define the Teradata system you wish to access.
Select This Field...

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

Enter a description. This is solely a comment field to describe the data


source name you used.

Name(s) or IP
address(es)

Enter the name(s) or IP address(es) of the Teradata Server of your


Teradata system.
Identify the host by either name (alias) or IP address. The setup routine
automatically searches for other systems that have similar name aliases.
Multiple server names may be entered by pulling the entries on separate
lines within this box.

Do not resolve alias


name to IP address

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

Select this option if will be logging on using integrated security


measures.

Mechanism

Select from the list of mechanisms that automatically appear in this box.
Leave this field blank to use the default mechanism.

Parameter

The authentication parameter is a password required by the selected


mechanism.

Username

Enter a user name.

Password

Enter a password to be used for the connection if you intend to use


Teradata SQL Assistant in an unattended (batch) mode. Entering a
password here is not very secure and is normally not recommended.

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.

ODBC Driver Setup for LOBs


When defining the ODBC Data Source, from the ODBC Driver Setup screen, use the Options
button to display the Teradata ODBC Driver Options screen and check the option - Use Native
Large Object Support.

Page 8

SQL Assistant

To access LOBs with SQL Assistant,


1) Click on the Options button
2) Check the "Use Native Large Object Support" option box

SQL Assistant

Page 9

Connecting to a Data Source


Connecting to a data source is the equivalent of logging on with SQL Assistant. You may
choose from any previously defined data source.
When the connection is complete, the Connect icon is disabled and the Disconnect icon (to its
right) is enabled.
To connect to multiple data sources:
1. Go to the Tools > Options > General tab.
2. Click Allow connections to multiple data sources (Query windows),
3. Follow the procedure for connecting to a data source.
Each new data source appears in the Database Explorer Tree and opens a new query window
with the data source name. To disconnect from one data source, click the Query window that is
connected to the data source and click the disconnect icon.

Page 10

SQL Assistant

1. Click on the Connection icon to connect to Teradata.


Provider options are Teradata .NET or ODBC.

2. Select a
data
source.

3. Complete the logon dialog box.

SQL Assistant

Page 11

Setting a Default Database via SQL


As seen on the previous slide, knowing which database is your default is an important concept
that is, if you dont want to spend a substantial amount of time always qualifying databases and
tables.
To avoid always having to qualify objects you can set a single default database that will allow
you to refrain from having to qualify that database name for objects referenced or owned by that
database. You may have only one default set at any time, and this default may be set using SQL
at any time during your session. Once invoked, this new default remains until it is changed
again, or until you log off. Each time you log on to the Teradata your default database will be
the same. This default need not be your own user name. It can be set to something other than
your user when your user was created.
If you recall, the minimum syntax required to create a user is:
CREATE USER abc AS PERM = 1000000, PASSWORD = lucky;
The default database for this user will be its own user (username is the default). It could have
been set to another database if this syntax were used to create abc. This would be your default
database if your user was created from our standardized script. Or it may have been changed by
your DBA.
CREATE USER abc AS
PERM = 1000000,
PASSWORD = lucky,
DEFAULT DATABASE = Emp_Views;
On the next frame, the new default database will be Employee_Sales.

Page 12

SQL Assistant

The default database assignment remains for a session until it is changed.


The original logon default is reacquired again at next logon.
Mouse-over the top of the Explorer Tree, as shown below, to display defaults shown.
Logged on as user XYZ.

Default database
is XYZ.

Changes the
default database to
Employee_Sales.

After issuing the database default request shown, which


database will be checked for the following?
HELP TABLE Employee;

Clicking on SQL
Statement in History
will recall it to the Query
Window later.

SQL Assistant

Page 13

Setting a Default Database via SQL Assistant


Here we see that a default database can be established through SQL Assistant. A default
database set in this tool will change any default database set at logon to a different database of
your choosing. Regardless, any default database may be changed using SQL as shown
previously.
When typing in a default database from the tool, it can either be manually typed with each logon,
or be more permanently (but not completely permanent) implemented by typing it in to the
TOOLS DEFINE DATA SOURCE path to add it so that you dont need to keep typing it in
for each logon.

A default database can be assigned through SQL Assistant like this.

You can override the default


database of your logon from
within SQL Assistant by setting it
here.
The pathway to this screen is:
TOOLS
DEFINE ODBC DATA SOURCE
SYSTEM DSN
CONFIGURE

This may also be typed


here at each logon.

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

Explorer Tree Option


The Database Explorer Tree feature of Teradata SQL Assistant displays an alphabetical listing of
databases and objects of the connected user. It further permits drilldown on individual objects to
view, column names, indexes and parameters as they apply. This is simply done by doubleclicking on a database name to expand the tree display for that database.
The Database Explorer Tree displays on the left side of the main Teradata SQL Assistant
window. 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.
Initially, the following Teradata databases are loaded into the Database Explorer Tree:

The User ID that was used to connect to the database


The users default database
The database "DBC"

To add additional databases:


1. Do one of the following:
With the Database Explorer Tree active, press Insert.
Right-click anywhere in the Database Explorer Tree, then select Add Database.
2. Type the database name to be added.
3. If you want the database loaded only for the current session, clear the check box. By
default, the check box is selected so the database will appear in the Database Explorer
Tree in future sessions.
The Database Explorer Tree allows you to drill down to show:

Page 16

Columns and indexes of tables


Columns of views
Parameters of macros
Parameters of stored procedures

SQL Assistant

The Database Explorer Tree displays an alphabetical listing of databases and


objects of the connected user.

It is not a database hierarchy, but a list of databases and objects that the
user needs to access.

To refresh a database, right-click on the database/user name and select


"Refresh".
To add another database to the Explorer
Tree, right-click on the Explorer Tree.

To expand an item/object, click on the


+ sign or double-click on the object name.

SQL Assistant

Page 17

Creating and Executing a Query


Queries are created by simply typing in the query text into the query window. It is not necessary
to add a semi-colon at the end of a command, unless you are entering multiple commands in a
single window. The query may be executed by clicking on the Execute icon in the toolbar.
This icon looks like a pair of footprints.
Execute actually executes the statements in the query one statement after the other and
optionally stops if one of the statements returns an error. Function key F5 can also be used to
execute queries serially.
Execute Parallel executes all statements at the same time - and is only valid if all the
statements are Teradata SQL/DML statements. This submits the entire query as a single request,
allowing the database to execute all the statements in parallel. Multiple answer sets are returned
in the Answerset window. Function key F9 can also be used to execute queries in parallel.

Creating statements (single and multi-queries)


To allow multiple queries:
1. Select Tools > Options
2. Select the General option
3. Select the option Allow Multiple Queries
Once this option is selected, you may open additional tabs in the query window. Each tab can
contain a separate query, and any of these queries can be executed. However, only one query
can be executed at a time.
You can create queries consisting of one or more statements.
A semicolon is not required when you enter one statement at a time. However, a semicolon
between the statements is required for two or more statements.
Each statement in the query is submitted separately to the database; therefore, your query may
return more than one Answerset.

Page 18

SQL Assistant

1. Create a query in the Query Window.


2. To execute a query use either the execute or the execute parallel buttons.
The execute button
window.

(or F5) serially executes all statements in the query

The execute parallel button


or (F9) executes all statements in the query
window in a single multi-statement request. These queries are effectively
executed in parallel.

Create
query in
Query
Window.

SQL Assistant

Page 19

Dragging Object Names to the Query Window


You can drag object names from the Database Explorer tree to the Query pane.
Click and drag the object from the Explorer tree to the Query pane. The name of the object
appears in the Query window.
Teradata SQL Assistant includes an option (Tools > Options) that allows objects to automatically
be qualified when dragging or pasting names from the Database Tree into the Query Window.
For example, if this option is checked, dragging the object "MyColumn" adds the parent object
"MyTable," and appears as "MyTable.MyColumn" in the Query Window.
Use the Ctrl key to add a comma after the object name when it is dragged to the Query Window.

Dragging Multiple Objects


Use the Shift and Ctrl keys to select more than one object from the Database Explorer Tree that
can be dragged to the Query window.

Page 20

Use the Ctrl key to select additional objects.


Use the Shift key to select a range of objects.

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.

Ctrl key was held to include comma.

SQL Assistant

Page 21

Query Options
To submit any part of any query
1.
2.
3.
4.

Select Tools > Options.


Select the Query tab.
Check the option Submit only the selected Query text, when highlighted.
From the Query window, select the part of the query to submit by highlighting it.

Clearing the Query Window


The query window may be cleared using the Clear Query button on the tool bar.

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

Ensure a statement exists in the Query window.


Do one of the following:
From the Tool Bar, click the Format Query button.
Right-click in the Query window, then click Format Query
Press Ctrl+Q
Select Edit > Format 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

To submit any part of a query:


1. Using Tools > Options > Query
Check the option Submit only the selected Query text, when
highlighted
2. Highlight the text in the query window and execute
To clear the text in the query window, use the Clear Query button.
To format a query, click on the Format Query button.

Highlighted
query in
Query
Window.

SQL Assistant

Page 23

Viewing Query Results


The results of a query execution may be seen in the Answer Set window. Large answer sets may
be scrolled using the slide bars.
The Answerset window is a table that displays the results from a statement. You can sort the
output in a number of ways and print as bitmaps in spreadsheet format. Individual cells, rows,
columns or blocks of columns may be formatted to change the background and foreground color
as well as the font style, name and size. You can make other modifications such as displaying or
hiding gridlines and column headers.
The table may be resized by stretching the Answerset window using standard Windows sizing
techniques. Individual columns, groups of columns, rows or groups of rows may also be sized.
Output rows may be viewed as they are being retrieved from the database.

Sorting an Answerset Locally


There are two ways to sort an Answerset locally, quick sort or full sort. A quick sort sorts on a
single column. A full sort allows sorting by data in multiple columns.
To sort an Answerset using quick sort:

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.

To display decimal places:

Right-click in the Answerset cell you wish to change and select Decimal Places.
Select a number between 0 and 4.

To designate up to 14 decimal places:

Page 26

Right-click to bring up the Shortcut menu.


Click Format Cells to bring up the Format Cells dialog.
Under Numerics, select the desired number of decimal places.

SQL Assistant

To set defaults for Answersets, use the


Tools > Options > Answerset tab.

To format specific cells, right-click


on a cell or use the
icon.

SQL Assistant

Page 27

Using Query Builder


Query Builder provides the user with the ability to use templates for SQL commands, which
may then be modified by the user. This is a convenient way to create commands whose syntax is
complex or not easily remembered. Simply find the appropriate command, then drag and drop it
into the query window where it may then be customized.
The Query Builder window is a floating window you can leave open when you are working
within the main Teradata SQL Assistant window.
To access the Query Builder tool, do one of the following:

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.

Description of the Options


SQL Statements
When you choose the SQL Statements option, the statement list in the left pane shows each of
the statement types available on the current data source. These syntax examples reflect the SQL
syntax of the data source you are currently connected. For example, the Teradata syntax file is
Teradata.syn.
Procedure Builder
When you choose the Procedure Builder option, the left pane shows a list of statements that are
valid only when used in a CREATE or REPLACE procedure statement.
<User Defined>
You can create a user-defined syntax file using any text editor such as Notepad or Microsoft
Word. The name of the file must be custom.syn. The format of this file is the same as the other
syntax files except it has an additional line at the start of the file containing the name you wish to
see in the dropdown list in the Query Builder dialog.

Page 28

SQL Assistant

Query Builder provides the


user with the ability to use
templates for SQL
commands.
1. Select Query Builder from
the Help menu or use F2.

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

A history of recently submitted queries may be recalled by activating the Show


History feature. Key options available with the History window are:
All history rows are now 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.
Choose to capture all queries (successful or not), only successful queries, or
turn off history recording altogether.

Query is copied into Query Window.

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 "?."

Use a separate Answer window for:


Each Resultset - opens a new Answer window for each new result set
Each Query - opens a new Answer window for each new query, but uses tabs
within this window if the query returns multiple result sets. This is the default
setting.
Never - directs all query results to display in a single tabbed Answer window

General options (Tools > Options > General tab) that are available include:

Allow connections to multiple data sources.


Allow multiple queries per connection allows you to have multiple query
windows open simultaneously. New Queries are opened in new tabs.

Additional General options include:

Page 32

Separate Answerset windows


Date format
Display of NULL data values
Font size

SQL Assistant

Connecting to Multiple Data Sources


You can connect to multiple data sources. The Allow connections to multiple data sources
option must be checked with the General Options.
Each new data source appears in the Database Tree and opens a new query window with the data
source name. To disconnect from one data source, click the Query window that is connected to
the data source and click the disconnect icon.
The example on the next frame shows two connects to two different systems (tdt5-1 and tdt6-1).

A separate query window is opened for each data source connection.

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.

Additional Tools menu options include:

Explain runs an Explain function on the SQL


statements in the Query window and display the
results in the Answerset window.

List Tables displays the Table List dialog box


where you can enter the name of the database
and the resulting list of tables or view displays in
an Answerset window.

List Columns displays the Column List dialog


box where you can list the columns in a particular
table/view and the resulting list of columns
displays in an Answerset window.

Disconnect disconnects from the current data


source.

Change Password change your Teradata


password.

Compact History reclaim space that may have


been lost when history rows were deleted.

Options establish various options for queries,


answersets, import/export operations, etc.

Page 34

SQL Assistant

Importing/Exporting Large Object Files


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 when defining ODBC driver for
Teradata. This option was discussed earlier in this module.

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

To import a LOB, create a data file that


contains the names of the Large
Objects.

Use the Export/Import Options dialog


to specify the field delimiter.

The example in this module assumes


the fields in the imported file are TAB
separated.

SQL Assistant

Page 35

Importing a LOB into Teradata


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 when defining ODBC driver for
Teradata. This option was discussed earlier in this module.

To Import a LOB into Teradata


A data file needs to be created that contain the names of the LOB(s) to be imported. By default,
the data file needs to be located in the same folder as the LOB.
Assume the data file to import from contains four parameters or fields that are <tab> separated.
Example:
INSERT INTO TF VALUES (?,?,?,?B);
The parameter markers in this example are:
? The data for this parameter is read from the Import file. It is always a character string,
and will be converted to a numeric value if necessary.
?B The data for this parameter resides in a file that is in the same directory as the Import file.
The import file contains only the name of the file to be imported. The contents of the
file are loaded as a binary image (e.g., BLOB). You can also use ?? in place of ?B.
?C The data for this parameter resides in a file that is in the same directory as the import file.
The import file contains only the name of the file to be imported. Use this marker to
load a text file into a CHAR or CLOB column.

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

TF v1310 Student Manual.pdf


TF v1310 Lab Workbook.pdf

The various fields are separated by tabs.


2. Within SQL Assistant, from the File menu, select the "Import Data" option to
turn on the Import Data function.
3. Enter an INSERT statement within the Query window.
INSERT INTO TF VALUES (?, ?, ?, ?B);
4. In the dialog box that is displayed, choose the name of the file to import.
For example, enter or choose "TF Manual LOB.txt".
5. From the File menu, select the "Import Data" option to turn off the Import
Data function.

SQL Assistant

Page 37

Selecting from a Table with a LOB


To select from a table with a LOB, simply execute a SELECT statement. If LOB column is
projected, then a dialog box is displayed to enter the file name for the LOB.
Note that multiple files that are exported will have sequential numbers added to the file name.
In the example on the next frame, the file name was specified as TF_Manual. Therefore, the two
manuals that will be created are named:

TF_Manual001.pdf
TF_Manual002.pdf

With SQL Assistant, enter the following query:


SELECT * FROM TF ORDER BY 1;
The following dialog box is displayed to represent the data files to export the
LOBs into. Also specify the "File Type" as a known Microsoft file type
extension.

The answer set window


will include a link to
exported data files.

Page 38

SQL Assistant

Displaying a JPG within SQL Assistant


The Display as picture can be selected to display a JPG file within the answer set.
Optionally, the Also save picture to a file can be selected.
Note that large JPG files will display very large within the answer set window.
SELECT * FROM Photos ORDER BY 1;
Optionally, the "Display as picture " can
be selected to display a JPG file within the
answer set.

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.

Characteristics of Teradata SQL Assistant include:

Windows-based utility that can be used to submit SQL queries to the


Teradata database.

Provides the 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.

Page 40

SQL Assistant

You might also like