Top Banner

of 23

sql_assistant_web_tutorial_2

Apr 08, 2018

Download

Documents

Gaurav Bansal
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
  • 8/7/2019 sql_assistant_web_tutorial_2

    1/23

    Teradata SQL Assistant Web Hands-On Lesson

    Teradata SQL Assistant/Web Edition

    This product is designed to provide a simple way to execute and manage your queries against aTeradata, or other ODBC compliant database. SQL Assistant Web stores your queries for easy re-use, and provides you with an audit trail that shows the steps that produced your current results.

    Hands-On SQL Assistant!In this tutorial, experience the simplicity and ease of use of this powerful browser-based query tool.This hands-on session will show you some of the ways in which you can use this tool in order tomaximize your efficiency. Hands-on activities will include connecting to a Teradata database,executing a query, and manipulating the results. With the new write capabilites you will also be able tocreate new databases, make copies of existing databases, and put data into your own databases.

    Lesson

    In this short lesson we will:

    1. Start Teradata SQL Assistant/Web Edition

    2. Connect to a Teradata system3. Demonstrate SQL Assistant Web functions

    1. Start Teradata SQL Assistant/Web Edition

    To start SQL Assistant Web click on Execute Teradata SQL Assistant/Web Edition.

  • 8/7/2019 sql_assistant_web_tutorial_2

    2/23

    Teradata SQL Assistant Web Hands-On Lesson

    2. Login to Teradata SQL Assistant/Web Edition

    Login using your SQL Login, Password, Default Database (if applicable), and click OK. This is the

    login you entered when you created your Teradata SQL Assistant/Web Edition account.

    Since you have access to all databases, and you do not have an assigned Default Database, you mayenter one on the login screen.

    Entering a default database here is the same as using the database command in SQL Assistant (i.e.typing in and executing database db_watson to access db_watson). Imagine having a row of 3mimes, a red mime, a blue mime, and a green mime, that obey your commands. By default, you arelooking at the red mime. Any commands you issue apply only to the mime you are focusing on. Inorder to issue commands to the blue mime, you need to focus on that mime. Likewise, to issuecommands to the green mime, you will need to adjust your focus again. In the context of a Teradatadatabase, this is exactly what the database command does.

  • 8/7/2019 sql_assistant_web_tutorial_2

    3/23

    Teradata SQL Assistant Web Hands-On Lesson

    3. Teradata SQL Assistant/Web Edition

    SQL Assistant consists of a left frame to show the tree and a main window divided into 3 areas.

    A Query section where you enter the SQL query you wish to execute.

    A History section where information about previously executed queries are displayed.

    And an Answer Setsection where your query results are displayed.

    The tree on the left is used to view the databases. By default, you will see DBC and your login name.The database named after your login name has been granted perm space, which allows you to writedata to the database. This includes the ability to define databases, create table, and insert data.Further specifics regarding yourperm space will be discussed later in this document.

    If you entered a Default Database in Step 2, it will also appear in the tree at the left. If you want to addadditional databases, click Add above the tree on the left, and enter the desired database.

    Adding a database via this method allows you to view the database under the database tree. In orderto access the database you will need to use the database command (i.e. database db_watson) todirect 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, andProcedures.

  • 8/7/2019 sql_assistant_web_tutorial_2

    4/23

    Teradata SQL Assistant Web Hands-On Lesson

    As an example, add the database db_watson (if not already there). Click on the + sign next todb_watson, then click on the + sign next to Tables to expand.

  • 8/7/2019 sql_assistant_web_tutorial_2

    5/23

    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 yourhard drive) you can use the Browse to search. You can Load the query into the query section andclick Execute. You may also run the query by clicking Run. Once you have written a query, you maysave it by clicking on .

    Enter your query in the query window, verify the maximum number of rows you wish to return andclick 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 willsee a brief description of the error on the bottom left of your screen. If you want to see more pages ofyour history, click on the numbers located above the Clear History button. You may also clear theentire 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 byclicking 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 Querysection. Then click Execute. If you would like to add a brief notation about the query, click on Edit nextto the query, and add your comments.

    5. When you have finished using Teradata SQL Assistant/Web Edition, please click on thebutton on the top of the screen to disconnect. You may use your browser to go back to theTeradata University Network home page.

  • 8/7/2019 sql_assistant_web_tutorial_2

    6/23

    Teradata SQL Assistant Web Hands-On Lesson

    Notes on Write Access and Data Loading

    Write Access

    A new feature on TUN Web is write access. Students are automatically assigned the permanentspace they need to create tables, indexes, and all database structures as well as copy and insertdata. This perm space appears in the directory tree with a name that is the students login id. Write

    access to their perm space is automatically granted to students when they register for a course. Touse this space, students must change from the default database for your course to their perm spaceby issuing the database command, referring to their perm space name as the. Students may manage the rights for other students to use their perm spacethrough SQL GRANT and REVOKE commands.

    Instructor accounts are granted similar privileges but with the additions of more permanent space andselect access on student accounts in your courses.

    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 thisfrom each source.

    From Excel:

    1. Open your spreadsheet with data

    2. Click on the first cell, cell A1

    Step 2

  • 8/7/2019 sql_assistant_web_tutorial_2

    7/23

    Teradata SQL Assistant Web Hands-On Lesson

    3. In the menu bar, go to Insert->Columns

    4. Enter insert into values(, replacing with your desired table name andomitting the quotation marks as shown in the screen capture below for the example tablesample_table.

    Step 4

    5. Select and highlight the first column, A

  • 8/7/2019 sql_assistant_web_tutorial_2

    8/23

    Teradata SQL Assistant Web Hands-On Lesson

    6. In the menu bar, go to Edit->Fill->Down

    Step 6

  • 8/7/2019 sql_assistant_web_tutorial_2

    9/23

    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 clickingand dragging on that cell or by clicking on that cell, holding down the shift key, and clicking onthe last row.

    10. In the menu bar, go to Edit->Fill->Down. This places a closed parenthesis at the end of eachrow.

    11. In the menu bar, go to File->Save As

    Note: Teradata Data Types have different requirements. For example, in the datasetabove, character strings are enclosed by quotation marks (i.e. Sam). For moreinformation about data types, please reference the Teradata User Manuals: DataTypes and Literals PDF document available via the Teradata Database User

    Manuals link on the main page.

  • 8/7/2019 sql_assistant_web_tutorial_2

    10/23

    Teradata SQL Assistant Web Hands-On Lesson

    12. Select CSV (Comma delimited) (*.csv) as the File Type

    Step 12

    13. Save the file

  • 8/7/2019 sql_assistant_web_tutorial_2

    11/23

    Teradata SQL Assistant Web Hands-On Lesson

    14.Now open the file you saved in Notepad. Note pad can be found by clicking on Start, Run, typenotepad, and press enter.

    15. In the menu bar, go to Edit->Replace

    16. Under Find what type in (, without the quotation marks

    17. Under Replace with type in( without the quotation marks

  • 8/7/2019 sql_assistant_web_tutorial_2

    12/23

    Teradata SQL Assistant Web Hands-On Lesson

    Steps 16 and 17

    18. Click on the Replace All button

    19. In the menu bar, go to Edit->Replace

    20. Under Find what type in ,) without the quotation marks

    21. Under Replace with type in) without the quotation marks

    22. Click on the Replace All button

    23. In the menu bar, go to File->Save

  • 8/7/2019 sql_assistant_web_tutorial_2

    13/23

    Teradata SQL Assistant Web Hands-On Lesson

    24.Login to the SQL Assistant Web Edition utility and under Default Database type in your SQLusername. Alternatively, if you are already logged-in to SQL Assistant, issue the databasecommand to switch to your perm space as the database to use.

    Step 24

  • 8/7/2019 sql_assistant_web_tutorial_2

    14/23

    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 SQLcommands to create the table, indexes, and constraints you wish to use. For example, tocreate a table, type in the SQL statement in the query window and click on the button, asillustrated below:

    Step 25

  • 8/7/2019 sql_assistant_web_tutorial_2

    15/23

    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 withoutthe quotation marks and where is replaced by the name of the table you created:select * from order by 1;

    The order by 1 clause sorts the answer set alphabetically by the first column.

    Step 29

  • 8/7/2019 sql_assistant_web_tutorial_2

    16/23

    Teradata SQL Assistant Web Hands-On Lesson

    From Microsoft Access:

    1. Run Microsoft Access

    2. Open your Microsoft Access MDB file.

    3. In Tables view, select/highlight a table

    4. In the menu bar, go to File->Export

    Step 4

  • 8/7/2019 sql_assistant_web_tutorial_2

    17/23

    Teradata SQL Assistant Web Hands-On Lesson

    5. Specify the filename and location you want to export to

    6. Select data type: Microsoft Excel 97-2003 (*.xls)

    Steps 5 and 6

    7. Click Export

    8. Run Microsoft Excel

    9. Open the file you just created from Export

  • 8/7/2019 sql_assistant_web_tutorial_2

    18/23

    Teradata SQL Assistant Web Hands-On Lesson

    10. Click on Cell A1

    Step 10

  • 8/7/2019 sql_assistant_web_tutorial_2

    19/23

    Teradata SQL Assistant Web Hands-On Lesson

    11. In the menu bar, go to Edit->Delete->Entire Row

    Step 11

    12. Save and Continue with Step 2 of the Microsoft Excel instructions above.

  • 8/7/2019 sql_assistant_web_tutorial_2

    20/23

    Teradata SQL Assistant Web Hands-On Lesson

    From Teradata (table copy):

    1. These instructions are meant to copy all data from a table customer_t located in a databasedb_pvfc to your SQL account. Both customer_t and db_pvfc should be replaced by the actualnames of the table and database you wish to copy from.

    2. Login to the SQL Assistant Web Edition utility and under Default Database type in your SQLusername

    Step 2

  • 8/7/2019 sql_assistant_web_tutorial_2

    21/23

    Teradata SQL Assistant Web Hands-On Lesson

    3. For illustration purposes, assume you wanted to create your own copy of the customer tablefrom the db_pvfc database stored on the SQL Assistant server.

    Enter the following SQL statement without the quotation marks in the query window and clickthe 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 thecustomer_t table; you can, of course, write any SQL select statement to copy only selectrows):

    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;

  • 8/7/2019 sql_assistant_web_tutorial_2

    22/23

    Teradata SQL Assistant Web Hands-On Lesson

    From Teradata (to create your own copy of one of the existing databases available with SQLAssistant):

    1. These instructions are meant to copy all tables within a database db_pvfc_std to your SQLaccount. Note that db_pvfc_std should be replaced by the name of the database you wish tocopy 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 anexisting database.

    Additionally, script files for each of the existing databases have been generated and areavailable through the Database Descriptions link on the bottom of the SQL Assistant loginpage.

    3. Login to the SQL Assistant Web Edition utility and under Default Database type in your SQLusername

    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

    http://tunweb.teradata.ws/tunstudent/tunscripts/copy_db_pvfc_std.txthttp://tunweb.teradata.ws/tunstudent/tunscripts/copy_db_pvfc_std.txt
  • 8/7/2019 sql_assistant_web_tutorial_2

    23/23