Sunteți pe pagina 1din 17

Teradata Utilities

Agenda
BTEQ FastExport Fastload Multiload Tpump INMOD and OUTMOD processing

BTEQ

AN INTRODUCTION TO BTEQ

Why it is called BTEQ? Logging on to BTEQ Submitting SQL in BTEQs Interactive Mode Submitting SQL in BTEQs 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

BTEQ - Introduction
BTEQ 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

BTEQ -

BTEQ execution in interactive mode

Submitting SQL in BTEQs 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.

BTEQ Mode

Submitting SQL in BTEQs Batch

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

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_Customer SELECT A.Account_Number ,C.Last_Name ,C.First_Name ,A.Balance_Current FROM Accounts A INNER JOIN Account_Customer AC ON C.Customer_Number = AC.Customer_Number INNER JOIN Customer C ON A.Account_Number = AC.Account_Number WHERE A.Balance_Current > 1000000; .QUIT

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.

BTEQ MODE

EXPORT EXAMPLE USING RECORD (DATA)

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.

BTEQ MODE

EXPORT EXAMPLE USING FIELD (REPORT)

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

.EXPORT RESET .QUIT

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

BTEQ - Return Codes


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

Return Code
00 02 04 08 12 .

Description
Job completed with no errors. User alert to log on to the Teradata DBS. Warning error. User error. Severe internal error.

BTEQ -Commands
BTEQ 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 .

ABORT

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. - Abort any and all active running requests and transactions and EXIT BTEQ.

BTEQ Session control Commands

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

HALT EXECUTION LOGOFF LOGON QUIT SECURITY -

- End the current session or sessions, but do not exit BTEQ. - Starts a BTEQ Session. Every user, application, or utility must LOGON to Teradata to establish a session. - End the current session or sessions and exit BTEQ. 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 SHOW VERSIONS - Displays all of the BTEQ control command options currently configured. - Displays the BTEQ software release versions..

BTEQ File Control Commands


These 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 FORMAT Open a file with a specific format to transfer information directly from the Teradata database. - 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.

These commands control the sequence in which Teradata commands operate.

BTEQ Sequence Control Commands

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.

IFTHEN

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.

These 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.

BTEQ Format Control Commands

S-ar putea să vă placă și