Teradata SQL Assistant Web Hands-On Lesson
Teradata SQL Assistant Web Hands-On Lesson
Teradata SQL Assistant Web Hands-On Lesson
Lesson
In this short lesson we will:
1. Start Teradata SQL Assistant/Web Edition
2. Connect to a Teradata system
3. Demonstrate SQL Assistant Web functions
Adding a database via this method allows you to view the database under the database tree. In order
to access the database you will need to use the database command (i.e. ‘database db_watson’) to
direct your SQL commands to that particular database.
If you click on the + sign next to the database you can expand to see the tables, views, Macros, and
Procedures.
Teradata SQL Assistant Web Hands-On Lesson
As an example, add the database ‘db_watson’ (if not already there). Click on the + sign next to
db_watson, then click on the + sign next to Tables to expand.
Teradata SQL Assistant Web Hands-On Lesson
4. Executing Queries
The top section is used to enter your query. If you have a query stored (query in a text format on your
hard drive) you can use the Browse to search. You can Load the query into the query section and
click Execute. You may also run the query by clicking Run. Once you have written a query, you may
save it by clicking on .
→ Enter your query in the query window, verify the maximum number of rows you wish to return and
click the button. If you want to execute multiple queries in parallel, click the button.
When you execute a query, you will see your query in the History section. If there is an error, you will
see a brief description of the error on the bottom left of your screen. If you want to see more pages of
your history, click on the numbers located above the Clear History button. You may also clear the
entire history, or save it to a file.
The results of your query will be displayed the Answer Set section. You can sort the answer set by
clicking on the underlined column name of the screen.
If you want to run the query again, you can click on Select and your query will appear in the Query
section. Then click Execute. If you would like to add a brief notation about the query, click on Edit next
to the query, and add your comments.
5. When you have finished using Teradata SQL Assistant/Web Edition, please click on the
button on the top of the screen to disconnect. You may use your browser to go back to the
Teradata University Network home page.
Teradata SQL Assistant Web Hands-On Lesson
Batch Loading
The following are instructions for how to load data into your perm space from an Excel spreadsheet, a
Microsoft Access database, or from another Teradata database. We will illustrate below how to do this
from each source.
From Excel:
1. Open your spreadsheet with data
2. Click on the first cell, cell A1
Step 2
Teradata SQL Assistant Web Hands-On Lesson
Step 4
Step 6
Teradata SQL Assistant Web Hands-On Lesson
7. Click on the empty cell at the end of the first data row.
8. Enter “);” without the quotation marks.
Steps 7 and 8
9. Now highlight all of the cells in the column from the first data row to the last either by clicking
and dragging on that cell or by clicking on that cell, holding down the ‘shift’ key, and clicking on
the last row.
10. In the menu bar, go to Edit->Fill->Down. This places a closed parenthesis at the end of each
row.
11. In the menu bar, go to File->Save As…
Note: Teradata Data Types have different requirements. For example, in the dataset
above, character strings are enclosed by quotation marks (i.e. ‘Sam’). For more
information about data types, please reference the “Teradata User Manuals: Data
Types and Literals” PDF document available via the “Teradata Database User
Manuals” link on the main page.
Teradata SQL Assistant Web Hands-On Lesson
Step 12
14. Now open the file you saved in Notepad. Note pad can be found by clicking on Start, Run, type
‘notepad’, and press enter.
Steps 16 and 17
24. Login to the SQL Assistant Web Edition utility and under Default Database type in your SQL
username. Alternatively, if you are already logged-in to SQL Assistant, issue the ‘database’
command to switch to your perm space as the database to use.
Step 24
Teradata SQL Assistant Web Hands-On Lesson
25. If you have not already done so, create a table for your data by executing the proper SQL
commands to create the table, indexes, and constraints you wish to use. For example, to
create a table, type in the SQL statement in the query window and click on the button, as
illustrated below:
Step 25
Teradata SQL Assistant Web Hands-On Lesson
26. Click on the button at the top. This will bring up a new window. Then click on ‘Browse’.
27. Open your CSV file that you saved earlier
Steps 26 and 27
28. Click the ‘Run’ button to execute the statements in your .csv file
29. Verify that the data were loaded correctly by executing the following SQL statement without
the quotation marks and where <mytable> is replaced by the name of the table you created:
“select * from <mytable> order by 1;”
The ‘order by 1’ clause sorts the answer set alphabetically by the first column.
Step 29
Teradata SQL Assistant Web Hands-On Lesson
Step 4
Teradata SQL Assistant Web Hands-On Lesson
Steps 5 and 6
7. Click Export
8. Run Microsoft Excel
9. Open the file you just created from Export
Teradata SQL Assistant Web Hands-On Lesson
Step 10
Teradata SQL Assistant Web Hands-On Lesson
Step 11
12. Save and Continue with Step 2 of the Microsoft Excel instructions above.
Teradata SQL Assistant Web Hands-On Lesson
Step 2
Teradata SQL Assistant Web Hands-On Lesson
3. For illustration purposes, assume you wanted to create your own copy of the customer table
from the db_pvfc database stored on the SQL Assistant server.
Enter the following SQL statement without the quotation marks in the query window and click
the ‘Execute’ button:
“create table customer_t as db_pvfc.customer_t with no data;”
Step 3
4. Now repeat Step 3 with the following statement instead (this will make a complete copy of the
customer_t table; you can, of course, write any SQL select statement to copy only select
rows):
“insert into customer_t select * from db_pvfc.customer_t;”
5. Verify that the table was copied correct by executing the following statement:
“select * from customer_t order by 1;”
Teradata SQL Assistant Web Hands-On Lesson
From Teradata (to create your own copy of one of the existing databases available with SQL
Assistant):
1. These instructions are meant to copy all tables within a database db_pvfc_std to your SQL
account. Note that db_pvfc_std should be replaced by the name of the database you wish to
copy from.
2. To start, download and save the following text file:
http://tunweb.teradata.ws/tunstudent/tunscripts/copy_db_pvfc_std.txt
This text file is essentially a preassembled script file with a set of SQL commands to copy an
existing database.
Additionally, script files for each of the existing databases have been generated and are
available through the ‘Database Descriptions’ link on the bottom of the SQL Assistant login
page.
3. Login to the SQL Assistant Web Edition utility and under Default Database type in your SQL
username
4. Click on the ‘Browse’ button. Locate and open copy_db_pvfc_std.txt.
5. Click on the ‘Run’ button to execute the SQL statements within copy_db_pvfc_std.txt
Teradata SQL Assistant Web Hands-On Lesson
That is all for our quick tour of the Teradata SQL Assistant/Web Edition.
In conclusion, we hope that we have given you a brief insight into some of the capabilities of Teradata
SQL Assistant/Web Edition, and that you will be motivated to learn more of its capabilities. The SQL
Assistant help file (located in the upper right hand corner of the SQL Assistant screen), and the User’s
Guide (located on the Teradata University Network home page under the Teradata SQL
Assistant/Web Edition executable) will give you a detailed description of the product.