Teradata Utilities[1]

17
Teradata Utilities

Transcript of Teradata Utilities[1]

Page 1: Teradata Utilities[1]

Teradata Utilities

Page 2: Teradata Utilities[1]

Agenda

• BTEQ • FastExport• Fastload• Multiload• Tpump• INMOD and OUTMOD processing

Page 3: Teradata Utilities[1]

BTEQ AN INTRODUCTION TO BTEQ

•Why it is called BTEQ? •Logging on to BTEQ •Submitting SQL in BTEQ’s Interactive Mode •Submitting SQL in BTEQ’s Batch Mode •USING BTEQ CONDITIONAL LOGIC •USING BTEQ TO EXPORT DATA •BTEQ EXPORT EXAMPLE USING RECORD (DATA) MODE •BTEQ EXPORT EXAMPLE USING FIELD (REPORT) MODE •BTEQ IMPORT EXAMPLE •BTEQ RETURN CODES •BTEQ COMMANDS

Page 4: Teradata Utilities[1]

BTEQ - IntroductionBTEQ is often referred to as the Basic TEradata Query tool

•Submit SQL in either a batch or interactive environment•Tool for importing and exporting data•Users can submit BTEQ jobs from batch scripts•Error checking and conditional logic can be implemented

Logging on to BTEQ:

Interactive mode:.logon ipaddress(or)servername/username<password>

Batch mode:.logon ip address(or)servername/username,password

Page 5: Teradata Utilities[1]

BTEQ - Submitting SQL in BTEQ’s Interactive Mode

BTEQ execution in interactive mode

Type at command prompt: Logon with TDPID and USERNAME.

.LOGON cdw/sql01;

Then enter PASSWORD at the second prompt.

Password: XXXXX

Enter your BTEQ/SQL Request or BTEQ Command.BTEQ will respond and is waiting for a command.

SELECT * FROM Employee_Table WHERE Dept_No = 400;

*** Query Completed. 2 rows found. 5 Columns returned.

*** Total elapsed time was 1 second.BTEQ displays information about the answer set.

Page 6: Teradata Utilities[1]

BTEQ - Submitting SQL in BTEQ’s Batch Mode

To submit a job in Batch mode :

BTEQ < Scriptpath > logfilepath

Sample bteq script:

.LOGON 127.0.0.1/dbc,dbc /* Logon statement */

SELECT * FROM Employee_Table WHERE Dept_No = 400;

.LOGOFF /* Logging off of Teradata */

Note: Instead having logon details in script,create a script to contain only logon credentials.RUN FILE =logondb.txt

Page 7: Teradata Utilities[1]

BTEQ - CONDITIONAL LOGIC .RUN FILE =logondb.txt

DELETE FROM Million_Dollar_Customer ALL;

.IF ERRORCODE = 0 THEN .GOTO TableOK

CREATE TABLE Million_Dollar_Customer(Account_Number INTEGER,Customer_Last_Name VARCHAR(20),Customer_First_Name VARCHAR(15),Balance_Current DECIMAL(9,2));

.LABEL TableOK

INSERT INTO Million_Dollar_CustomerSELECT A.Account_Number,C.Last_Name,C.First_Name,A.Balance_CurrentFROM Accounts A INNER JOIN Account_Customer AC ON C.Customer_Number = AC.Customer_NumberINNER JOIN Customer CON A.Account_Number = AC.Account_NumberWHERE A.Balance_Current > 1000000;

.QUIT

Page 8: Teradata Utilities[1]

BTEQ - TO EXPORT DATA Data can be exported from Teradata database to a file

Format of the EXPORT command:.EXPORT <mode> {FILE | DDNAME } = <filename> [, LIMIT=n]

Types of export modes:Record Mode: Also called DATA mode Set by .EXPORT DATA. Date written in native format

Field Mode: Also called REPORT mode Set by .EXPORT REPORT Default mode for BTEQ Can be understood with text editor

Indicator Mode: Set by .EXPORT INDICDATA. Writes the data in data mode with additional feature of recognizing Null values.

DIF Mode: Known as Data Interchange Format, Allows users to export data from Teradata to be directly utilized for spreadsheet applications like Excel, FoxPro and Lotus.

Page 9: Teradata Utilities[1]

BTEQ - EXPORT EXAMPLE USING RECORD (DATA) MODE Sample script with RECORD mode:

.RUN FILE =logondb.txt

.EXPORT DATA FILE = C:\EMPS.TXT

SELECT * FROM Employee_Table WHERE Dept_No = 400;

.QUIT

Note:A period starting a line indicates a BTEQ command. If there is no period, then the command is an SQL command.

Page 10: Teradata Utilities[1]

BTEQ - EXPORT EXAMPLE USING FIELD (REPORT) MODE Sample script with FIELD(REPORT) mode:

.RUN FILE =logondb.txt

.EXPORT REPORT FILE = C:\EMPS.TXT

SELECT * FROM Employee_Table WHERE Dept_No = 400;

.QUIT

ONE MORE EXAMPLE:

.RUN FILE =logondb.txt

.SET WIDTH 90

.SET FORMAT ON

.SET HEADING ‘Employee Profiles’

.EXPORT REPORT FILE = C:\EMP_REPORT.TXT

.EXPORT RESET

.QUIT

WIDTH specifies the width of screen displays and printed reports, based on characters per line.

FORMAT command allows the ability to enable/inhibit the page-oriented format option.

HEADING command specifies a header that will appear at the top every page of a report.

Page 11: Teradata Utilities[1]

BTEQ - IMPORT Example

Bteq script for importing data with DATA mode option

.SESSIONS 4

.LOGON 127.0.0.1/dbc,dbc;

.IMPORT DATA FILE = C:\EMPS.TXT, SKIP = 2

.QUIET ON

.REPEAT *

.QUIT

Page 12: Teradata Utilities[1]

BTEQ - Return CodesReturn codes are two-digit values that BTEQ returns to the user after completing each job or taskValue of the return code indicates the completion status of the job or task as follows:

Return Code Description

00 Job completed with no errors.

02 User alert to log on to the Teradata DBS.

04 Warning error.

08 User error.

12 Severe internal error.

.

Page 13: Teradata Utilities[1]

BTEQ -CommandsBTEQ commands in Teradata are designed for flexibility

Commands are classified in to four areas:

•Session Control Commands

•File Control Commands

•Sequence Control Commands

•Format Control Commands

.

Page 14: Teradata Utilities[1]

BTEQ – Session control CommandsABORT - Abort any and all active running requests and transactions, but do not exit BTEQ.

DEFAULTS - Reset all BTEQ Format command options to their defaults. This will utilize the default configurations.

EXIT - Immediately end the current session or sessions and exit BTEQ.

HALT EXECUTION - Abort any and all active running requests and transactions and EXIT BTEQ.

LOGOFF - End the current session or sessions, but do not exit BTEQ.

LOGON - Starts a BTEQ Session. Every user, application, or utility must LOGON to Teradata to establish a session.

QUIT - End the current session or sessions and exit BTEQ.

SECURITY - Specifies the security level of messages between a network-attached system and the Teradata Database.

SESSIONS - Specifies the number of sessions to use with the next LOGON command.

SESSION CHARSET - Specifies the name of a character set for the current session or sessions.

SESSION SQLFLAG - Specifies a disposition of warnings issued in response to violations of ANSI syntax. The SQL will still run, but a warning message will be provided. The four settings are FULL, INTERMEDIATE, ENTRY, and NONE.

SESSION TRANSACTION - Specifies whether transaction boundaries are determined by Teradata SQL or ANSI SQL semantics.

SHOW CONTROLS - Displays all of the BTEQ control command options currently configured.SHOW VERSIONS - Displays the BTEQ software release versions..

Page 15: Teradata Utilities[1]

BTEQ – File Control CommandsThese BTEQ commands are used to specify the formatting parameters of incoming and outgoing information. This includes identifying sources and determining I/O streams.

ERROROUT - Write error messages to a specific output file.

EXPORT Open a file with a specific format to transfer information directly from the Teradata database.

FORMAT - Enable/inhibit the page-oriented format command options.

IMPORT - Open a file with a specific format to import information into Teradata.

INDICDATA - One of multiple data mode options for data selected from Teradata. The modes are INDICDATA, FIELD, or RECORD MODE.

OS - Execute an MS-DOS, PC-DOS, or UNIX command from inside BTEQ.

QUIET - Limit BTEQ output displays to all error messages and request processing statistics.

REPEAT - Submit the next request a certain amount of times

RUN - Execute Teradata SQL requests and BTEQ commands directly from a specified run file.

Page 16: Teradata Utilities[1]

BTEQ – Sequence Control CommandsThese commands control the sequence in which Teradata commands operate.

ERRORLEVEL - Assign severity levels to particular error numbers.

EXIT - End the current session or sessions and exit BTEQ.

GOTO - Skip all intervening commands and resume after branching forward to the specified label.

HANG - Pause BTEQ processing for a specific amount of time.

IF…THEN Test a stated condition, and then resume processing based on the test results.

LABEL The GOTO command will always GO directly TO a particular line of code based on a label.

MAXERROR Specifies a maximum allowable error severity level.

QUIT End the current session or sessions and exit BTEQ.

REMARK Place a comment on the standard output stream.

Page 17: Teradata Utilities[1]

BTEQ – Format Control CommandsThese commands control the formatting for Teradata and present the data in a report mode to the screen or printer.

ECHOREQ - Enable the Echo required function in BTEQ returning a copy of each Teradata SQL request and BTEQ command to the standard output stream.FOLDLINE - Split or fold each line of a report into multiple lines.FOOTING - Specify a footer to appear at the bottom of every report page.NULL - Specifies a character or string of characters to represent null values returned from Teradata.OMIT - Omit specific columns from a report.PAGEBREAK - Ejects a page whenever a specified column changes values.PAGELENGTH - Specifies the page length of printed reports based on lines per page.RECORDMODE - One of multiple data mode options for data selected from Teradata. (INDICDATA, FIELD, or RECORD).RETCANCEL - Cancel a request when the specified value of the RETLIMIT command option is exceeded.RETLIMIT - Specifies the maximum number of rows to be displayed or written from a Teradata SQL request.RETRY - Retry requests that fail under specific error conditions.RTITLE - Specify a header appearing at the top of all pages of a report.SEPARATOR - Specifies a character string or specific width of blank characters separating columns of a report.SIDETITLES - Place titles to the left or side of the report instead of on top.SKIPLINE - Inserts blank lines in a report when the value of a column changes specified values.SUPPRESS - Replace each and every consecutively repeated value with completely-blank character strings.

TITLEDASHES -Display dash characters before each report line summarized by a WITH clause.UNDERLINE - Display a row of dash characters when the specified column changes values.WIDTH - Specifies the width of screen displays and printed reports, based on characters per line.