Download - Introduction to Teradata Client Tools. 2 Introduction to Teradata SQL OBJECTIVES : Teradata Product Components. Accessing Teradata – Database

Transcript
Page 1: Introduction to Teradata Client Tools. 2 Introduction to Teradata SQL  OBJECTIVES :  Teradata Product Components.  Accessing Teradata – Database

Introduction to Teradata Client Tools

Page 2: Introduction to Teradata Client Tools. 2 Introduction to Teradata SQL  OBJECTIVES :  Teradata Product Components.  Accessing Teradata – Database

2

Introduction to Teradata SQL

OBJECTIVES : Teradata Product Components. Accessing Teradata – Database / User Teradata SQL Assistant Teradata Administrator

Page 3: Introduction to Teradata Client Tools. 2 Introduction to Teradata SQL  OBJECTIVES :  Teradata Product Components.  Accessing Teradata – Database

3

Teradata Database 12.0Product Components

Page 4: Introduction to Teradata Client Tools. 2 Introduction to Teradata SQL  OBJECTIVES :  Teradata Product Components.  Accessing Teradata – Database

4

Teradata User/Database Organization

To ensure space will always be available for spool ...

DBC

Spool_Reserve

SystemFE

SysAdmin

CrashDumps

Sys_Calendar

Users

View, Macro, and Stored Procedure Databases

Database(1)

Database(1)

Database(1)

Database(2)

QCD

SYSDBA

TemporaryTable

Databases

CREATE DATABASE Spool_Reserve AS PERM = spool_amount ;

(The space used by Spool_Reserve will reduce the total available permanent space in the system by 20% to 25%.)

Page 5: Introduction to Teradata Client Tools. 2 Introduction to Teradata SQL  OBJECTIVES :  Teradata Product Components.  Accessing Teradata – Database

5

Users and Databases

Human_Resources Accounting

DBC

SYSDBA

PR01 PR02 PR03 BF01 BF02 BF03

Personnel Benefits

You can grant CREATE DATABASE authority to any user.

The user may then create other users and databases from:• The user’s own space, or• The space of another user or database (if authorized).

Page 6: Introduction to Teradata Client Tools. 2 Introduction to Teradata SQL  OBJECTIVES :  Teradata Product Components.  Accessing Teradata – Database

6

Start Teradata Service

• Run the Service Teradata Database Initiator• By Default this service is Manual in Demo. • You may need more Services to start based on the tools to explore.• This applies only for Demo CD

Page 7: Introduction to Teradata Client Tools. 2 Introduction to Teradata SQL  OBJECTIVES :  Teradata Product Components.  Accessing Teradata – Database

7

Teradata SQL Assistant

Page 8: Introduction to Teradata Client Tools. 2 Introduction to Teradata SQL  OBJECTIVES :  Teradata Product Components.  Accessing Teradata – Database

8

Teradata SQL Assistant

• Open the Teradata SQL Assistant.• This is the interface to work with the Teradata SQL

Page 9: Introduction to Teradata Client Tools. 2 Introduction to Teradata SQL  OBJECTIVES :  Teradata Product Components.  Accessing Teradata – Database

9

Connect to Database

Page 10: Introduction to Teradata Client Tools. 2 Introduction to Teradata SQL  OBJECTIVES :  Teradata Product Components.  Accessing Teradata – Database

10

Configure Database Connection

• By Default the Demo installation configures DemoTDAT as ODBC connection.• Password can be saved in the connection as below. If left blank, it prompts on logon.• In real-time situation the Server info includes the Server IP address. Nodes’ IPs in case of MPP.• DBC is a super user and default password is DBC

• Leave the user/password blank.

Page 11: Introduction to Teradata Client Tools. 2 Introduction to Teradata SQL  OBJECTIVES :  Teradata Product Components.  Accessing Teradata – Database

11

SQL Assistant – Different Windows

Explain each Window – Database Explorer Tree, Query Window, Answer Set Window, History Window

Page 12: Introduction to Teradata Client Tools. 2 Introduction to Teradata SQL  OBJECTIVES :  Teradata Product Components.  Accessing Teradata – Database

12

Try this out

Where is my DUAL SELECT 100*2; SELECT DATE; SELECT 10/3.000;Explore help user dbc; select * from users; help user financial; select * from Financial.accts; show table Financial.accts; help table Financial.accts;

Page 13: Introduction to Teradata Client Tools. 2 Introduction to Teradata SQL  OBJECTIVES :  Teradata Product Components.  Accessing Teradata – Database

13

SQL Assistant – Tools - Options

Page 14: Introduction to Teradata Client Tools. 2 Introduction to Teradata SQL  OBJECTIVES :  Teradata Product Components.  Accessing Teradata – Database

14

Default Database

Setting the Default Database As a valid user, you will normally have access rights to your

own user database and the objects it contains. You may also have permission to access objects in other databases.

The user name you logon with is usually your default database. (This depends on how you were created as a user.)

Select Database; --- Gives the Current DatabaseChanging the Default Database The DATABASE command is used to change your default

database. For example: DATABASE Financial;

sets your default database to Financial. Subsequent queries (assuming the proper privileges are held) are made against the Financial database.

Page 15: Introduction to Teradata Client Tools. 2 Introduction to Teradata SQL  OBJECTIVES :  Teradata Product Components.  Accessing Teradata – Database

15

HELP Commands: Database objects

The HELP Command is used to display information about database objects such as (but not limited to):

Databases and Users Tables Views Macros

HELP retrieves information about these objects from the Data Dictionary. Below are the syntactical options for various forms of the HELP command:

HELP Command

HELP DATABASE databasename; HELP USER username; HELP TABLE tablename; HELP VIEW viewname; HELP MACRO macroname; HELP COLUMN table or viewname.*; (all columns) HELP COLUMN table or viewname.colname . . ., colname; HELP INDEX tablename; HELP STATISTICS  tablename; HELP CONSTRAINT constraintname; HELP JOIN INDEX join_indexname; HELP TRIGGER triggername;

Page 16: Introduction to Teradata Client Tools. 2 Introduction to Teradata SQL  OBJECTIVES :  Teradata Product Components.  Accessing Teradata – Database

16

Lets Create an User for Self

Create a user for yourself. This user is used for all the exercises to be done during the training.

CREATE USER TESTUSERFROM DBCASPASSWORD=TESTUSERPERM=2000000SPOOL=3000000TEMPORARY = 1000000DEFAULT DATABASE = TESTUSER; 

GRANT SELECTON DBC TO TESTUSER;

Log off & log on using TESTUSER

Page 17: Introduction to Teradata Client Tools. 2 Introduction to Teradata SQL  OBJECTIVES :  Teradata Product Components.  Accessing Teradata – Database

17

Teradata SQL Extensions

Here is a list of Teradata extensions ADD_MONTHSBEGIN/ END TRANSACTION COLLECT/ DROP STATISTICS COMMENT ON CONCATENATION EXPLAINFALLBACKFORMATHELPINDEXLOCKING MACRO Facility

 • CREATE • REPLACE • DROP • EXECUTE

NULLIFZERO/ZEROIFNULL NAMED SUBSTR SHOW TRIM TITLE WITH WITH . . . BY

Page 18: Introduction to Teradata Client Tools. 2 Introduction to Teradata SQL  OBJECTIVES :  Teradata Product Components.  Accessing Teradata – Database

18

Session Mode – Teradata / ANSI

Teradata is ANSI Compliant. SQL Assistant can be run on Teradata & ANSI modes. Default options are different for Teradata & ANSI modes Session mode can be changed using options while defining the

Teradata ODBC connection

Page 19: Introduction to Teradata Client Tools. 2 Introduction to Teradata SQL  OBJECTIVES :  Teradata Product Components.  Accessing Teradata – Database

19

The HELP DATABASE Command

The HELP DATABASE command shows all objects in the database specified.

HELP DATABASE FINANCIAL;

Table/View/Macro name Kind accts T checking_acct T checking_tran T credit_acct T credit_tran T customer T

Objects may be recognized by their 'Kind' designation as follows:  Table= T   View = V  Macro= M  Trigger= G  Join Index= J  Stored Procedure= PThe '?' is how BTEQ displays a null, indicating that no user comments have been entered.

Similarly other HELP functions can be used.

Page 20: Introduction to Teradata Client Tools. 2 Introduction to Teradata SQL  OBJECTIVES :  Teradata Product Components.  Accessing Teradata – Database

20

The SHOW Command

The SHOW command displays the current Data Definition Language (DDL) of a database object (e.g., Table, View, Macro, Trigger, Join Index or Stored Procedure).

Sample Show Commands Command ReturnSHOW TABLE tablename; CREATE TABLE statement SHOW VIEW viewname; CREATE VIEW statement SHOW MACRO macroname; CREATE MACRO statement 

Page 21: Introduction to Teradata Client Tools. 2 Introduction to Teradata SQL  OBJECTIVES :  Teradata Product Components.  Accessing Teradata – Database

21

The SHOW TABLE Command

CREATE SET TABLE CUSTOMER_SERVICE.employee ,FALLBACK ,    NO BEFORE JOURNAL,    NO AFTER JOURNAL     (    employee_number INTEGER,    manager_employee_number INTEGER,    department_number INTEGER,     job_code INTEGER,    last_name CHAR(20) CHARACTER SET LATIN NOT CASESPECIFIC NOT NULL,    first_name VARCHAR(30) CHARACTER SET LATIN NOT CASESPECIFIC NOT NULL,    hire_date DATE NOT NULL,     birthdate DATE NOT NULL,     salary_amount DECIMAL(10,2) NOT NULL

) UNIQUE PRIMARY INDEX ( employee_number );

Page 22: Introduction to Teradata Client Tools. 2 Introduction to Teradata SQL  OBJECTIVES :  Teradata Product Components.  Accessing Teradata – Database

22

Test Default Options – Teradata Vs. ANSI

Database Financial;

CREATE TABLE TAB1(COL1 INTEGER,COL2 CHAR(2));

SHOW TABLE TAB1;

CREATE SET TABLE FINANCIAL.TAB1 ,NO FALLBACK , NO BEFORE JOURNAL, NO AFTER JOURNAL ( COL1 INTEGER, COL2 CHAR(2) CHARACTER SET LATIN NOT CASESPECIFIC)PRIMARY INDEX ( COL1 );

/* Disconnect and connect again in ANSI mode*/Database Financial;

CREATE TABLE FINANCIAL.TAB2(COL1 INTEGER,COL2 CHAR(2));

SHOW TABLE TAB2;

CREATE MULTISET TABLE TAB2 ,NO FALLBACK , NO BEFORE JOURNAL, NO AFTER JOURNAL ( COL1 INTEGER, COL2 CHAR(2) CHARACTER SET LATIN CASESPECIFIC)PRIMARY INDEX ( COL1 );

Page 23: Introduction to Teradata Client Tools. 2 Introduction to Teradata SQL  OBJECTIVES :  Teradata Product Components.  Accessing Teradata – Database

23

The SHOW VIEW Command

CREATE VIEW dept        (dept_num        ,dept_name        ,budget        ,manager)

AS SELECT department_number

       ,department_name        ,budget_amount        ,manager_employee_numberr

 FROM CUSTOMER_SERVICE.department;

Page 24: Introduction to Teradata Client Tools. 2 Introduction to Teradata SQL  OBJECTIVES :  Teradata Product Components.  Accessing Teradata – Database

24

The SHOW MACRO Command

CREATE MACRO get_depts AS (SELECT department_number

,department_name ,budget_amount ,manager_employee_number

FROM department;);

To get Some Macros from DBC----

select B.DatabaseName, A.TVMNAME from DBC.TVM A,

dbc.dbase Bwhere A.tablekind = 'M'and A.DatabaseId = B.DatabaseID

E.g: show macro DBC.ResOneNode;

Page 25: Introduction to Teradata Client Tools. 2 Introduction to Teradata SQL  OBJECTIVES :  Teradata Product Components.  Accessing Teradata – Database

25

Teradata Administrator

Page 26: Introduction to Teradata Client Tools. 2 Introduction to Teradata SQL  OBJECTIVES :  Teradata Product Components.  Accessing Teradata – Database

26

Teradata Administrator

Open Teradata Administrator.This tool is used to perform database administration tasks on the associated Teradata

Page 27: Introduction to Teradata Client Tools. 2 Introduction to Teradata SQL  OBJECTIVES :  Teradata Product Components.  Accessing Teradata – Database

27

Teradata Administrator – View Objects

Its like a TOAD tool for Oracle.It lists all the Objects in a selected Database/User. The list view can be changed using Database Menu Option as below

Page 28: Introduction to Teradata Client Tools. 2 Introduction to Teradata SQL  OBJECTIVES :  Teradata Product Components.  Accessing Teradata – Database

28

Different actions can be performed on a selected Object.Explore options on a Table

- Row Count, Browse, Space etc….

Teradata Administrator – Explore Objects

Page 29: Introduction to Teradata Client Tools. 2 Introduction to Teradata SQL  OBJECTIVES :  Teradata Product Components.  Accessing Teradata – Database

29

Teradata Administrator - Functions

Teradata Administrator provides an easy-to-use Windows-based graphical interface to the Teradata RDBMS Data Dictionary. You may use Teradata Administrator to perform the following functions:

•Create, Modify and Drop Users or Databases•Create Tables (using ANSI or Teradata syntax)•Grant or Revoke access/system rights•Copy Table, View or Macro definitions to another database, or to another system•Drop or Rename Tables, Views or Macros•Move space from one database to another•Run an SQL query

Page 30: Introduction to Teradata Client Tools. 2 Introduction to Teradata SQL  OBJECTIVES :  Teradata Product Components.  Accessing Teradata – Database

30

Exercise

•Exercise – Teradata SQL Assistant

•Exercise – Teradata Administrator

Page 31: Introduction to Teradata Client Tools. 2 Introduction to Teradata SQL  OBJECTIVES :  Teradata Product Components.  Accessing Teradata – Database

31

Q/AThank You