Commonly used Teradata BTEQ commands and Examples

  • Post author:
  • Post last modified:December 24, 2020
  • Post category:General
  • Reading time:14 mins read

The BTEQ stands for Basic Teradata Query is one of the commonly used tools to interact with Teradata server. BTEQ tool was the original way that SQL was submitted to Teradata as a means of getting an answer in a desired format. In this article, we will check commonly used Teradata BTEQ commands with some examples.

Commonly used Teradata BTEQ commands

Following BTEQ commands are commonly used when writing scripts.

BTEQ CommandDescription
=Repeats the previous Teradata SQL request a specified number of times.
AUTOKEYRETRIEVEThis control enables users to specify whether the database returns values of any fields associated with Identity Data in response to subsequent SQL Insert operations.
BRANCHMSGThis control enables users to specify whether the generation of messages that explain input instruction branching for GOTO skipping and conditional block bypassing is to be verbose or terse.
COMPILEDefines (creates or replaces) an SQL stored procedure in the database using an SPL input file.
DECIMALDIGITSThis control enables users to specify what precision the database should use for decimal values associated with subsequently issued SQL requests for non-Field Mode responses.
DEFAULTSRestores initial default settings for commands used to control:
ECHOREQThis control enables users to specify if a copy of the Teradata SQL requests and BTEQ commands should be placed in the standard output stream.
ENCRYPTIONThis control enables users to specify full-stream encryption of requests and responses is to be used at the request-level. 
ERRORLEVELThis control enables users to specify how database errors map to severity levels.
ERRORONDBSWARNINGThis control enables users to specify that database warnings are to be treated as though they are errors. 
ERROROUTThis control enables users to specify which output stream BTEQ is to use for writing error messages.
EXIT or QUITLogs off all database sessions and then exits BTEQ.
EXITONDELAYThis control enables users to specify the maximum time duration within which to allow a submitted SQL request to be processed before CLI will time out the request. When a timeout occurs, the BTEQ process will terminate. The timeout is triggered when either the database goes down or the duration is exceeded
EXPORTThis control enables users to specify the name, format and attributes of an export file that BTEQ uses to store records resulting from data-returning SQL requests.
EXPORTEJECTThis control enables users to specify whether the additional Page Advance ASA Carriage control character at the top of a REPORT format export file is to be suppressed when using z/OS BTEQ.
FOLDLINEThis control enables users to specify whether to split each line of a report into two or more lines after the specified columns.
FOOTINGThis control enables users to specify the footer text string that appears at the bottom of each page of a report.
FORMATThis control enables users to specify whether to apply report layout controls for returned rows using all default and user-defined settings for the formatting commands.
FORMCHARThis control enables users to specify the HEX numeric escape sequence to be used instead of a form-feed character, when printing reports.
FULLYEARThis control enables users to specify whether to use a four-digit year format (YYYY) in a report’s header, footer and title lines. The default is a two-digit year format (YY).
GOTOSkips over all intervening BTEQ commands and SQL statements until a specified label is encountered, then resumes processing as usual.
HANGCauses BTEQ to pause for a specified period of time.
HEADING and RTITLEHEADING – This control enables users to specify a header that appears at the top of each page of a report.
RTITLE – This control enables users to specify a title that appears at the top of each page of a report. Titles specified by the RTITLE command automatically include the date and page number.
HELP BTEQReturns a list of all available BTEQ commands and non-graphic representations of their syntax
IF, ELSEIF, ELSE, and ENDIFThe IF, ELSEIF, ELSE and ENDIF commands are used to conditionally execute portions of the input script
IMPORTThis control enables users to specify a file and its format, from which to process the record data for USING modifiers of subsequent SQL requests.
INDICATORMODEThis control enables users to specify whether Indicator Mode is to be used to return data rows from the database in response to SQL data-returning requests.
LABELIdentifies the point at which BTEQ resumes processing, as specified in a previous GOTO command.
LARGEDATAMODEThis control enables users to specify whether Multipart Indicator response mode for Large Data Object (LDO) retrieval is to be used.
LOGMECH  This control enables users to specify the logon mechanism, such as NTLM, KRB5, LDAP or TD2, which defines the security context under which the established sessions will operate.
LOGDATAThis control enables users to specify a character string that is used to supply non-Teradata-managed user credentials to an external authentication mechanism.
LOGOFFTerminates the user’s database sessions without exiting from BTEQ.
LOGONConnects a user to a Teradata database.
LOGONPROMPTThis control enables users to specify whether prompts and warnings related to conventional LOGON command use is to be bypassed.
MAXERRORThis control enables users to specify a maximum error severity level beyond which BTEQ terminates job processing.
MESSAGEOUTSpecifies the name of a file to which BTEQ is to redirect the contents that would normally get sent to the standard output stream.
NOTIFYThis control enables users to specify a user exit or pre-defined action when certain significant events occur. NOTIFY applies only to the SQL request that immediately follows it.
NULLThis control enables users to specify a character string, rather that the default “?”, to represent a null field value for Field Mode reports.
OMITThis control enables users to specify whether any columns are to be excluded from Field Mode reports for subsequent data-returning SQL statements.
OSSubmits an operating system command to a workstation-attached system.
PACKThis control enables users to specify the maximum number of import data file records that can be sent within an SQL request’s USING data buffer.
PAGEBREAKThis control enables users to specify whether a page eject is to be done whenever values for one or more specified columns change.
PAGELENGTHThis control enables users to specify the maximum number of lines for report form output.
QUIETThis control enables users to specify whether BTEQ output is limited to errors and request processing statistics. This may significantly decrease the amount of output and hence improve the overall response time.
RECORDLENGTHThis control enables users to specify the maximum record (row) length that can be processed within the current session for imports, exports and stdout hex-dump output.
RECORDMODEThis control enables users to specify whether Record mode is used to return data rows from the database in response to data-returning SQL requests. 
REMARKPrints the specified string to the standard output stream.
REPEATThis control enables users to specify the maximum number of times the next SQL request is to be submitted.
REPEATSTOPThis control enables users to specify whether a REPEAT operation should terminate if an error occurs for a request that indicates the request cannot be re-tried.
REPORTALIGNThis control enables users to specify the spacing used for Unicode report mode output.
RETCANCELThis control enables users to specify whether to cancel a request when the number of rows specified by the RETLIMIT command is exceeded.
RETLIMITThis control enables users to specify the maximum number of rows and columns displayed on the terminal or written to a file in response to an SQL statement.
RETRYThis control enables users to specify whether requests that fail under certain error conditions should be resubmitted.
RUNProcesses the SQL requests and BTEQ commands from the specified run file instead of stdin or a run file currently being processed.
SEPARATORThis control enables users to specify the width and contents of the string to be placed between the columns in a report.
SESSION CHARSETThis control enables users to specify the name of the character set for existing and future database sessions.
SESSION RESPBUFLENThis control enables users to specify the initial size of the client response buffer for future database sessions.
SESSION SQLFLAGThis control enables users to specify if warnings are to be issued in response to syntax errors in accordance with Federal Information Processing Standards (FIPS) Publications 127-2 and 127-3 for ANSI compliance.
SESSION TRANSACTIONThis control enables users to specify whether transaction boundaries are determined by Teradata SQL semantics or ANSI standards.
SESSION TWORESPBUFSThis control enables users to specify whether CLI double-buffering is active or inactive.
SESSIONSThis control enables users to specify the number of database sessions that BTEQ is to request be logged on when the LOGON command is next used.
SHOWPrints the last SQL request sent to the database to the standard output stream.
SHOW CONTROLSPrints current values for one or all BTEQ settings to the standard output stream.
SHOW ERRORMAPLists BTEQ’s severity levels currently mapped for database errors and warning codes.
SHOW VERSIONSLists version levels for BTEQ and the key Teradata software it depends on.
SIDETITLESThis control enables users to specify whether titles are to be positioned above or to the left side of data returned for SQL statements. 
SKIPDOUBLEThis control enables users to specify whether two blank lines are to be inserted in a report whenever the value of the indicated column changes.
SKIPLINEThis control enables users to specify whether one blank line is to be inserted in a report whenever the value of the indicated column changes.
STATEMENTINDEPENDENCEThis control enables users to specify whether the database is to return applicable statement-level errors as independent responses instead of failing an entire multi-statement request.
SUPPRESSThis control enables users to specify whether all consecutively repeated values in reports are to be replaced with space characters.
TDPThis control enables users to specify a new default tdpid for subsequent logons.
TIMEMSGThis control enables users to specify whether any elapsed or total query time messages are to be printed.
TITLEDASHESThis control enables users to specify whether a line of dash characters is to be printed above the column data and aggregate data returned for SQL statements.
TMSMMSGThis control enables users to specify whether to print diagnostic messages that describe loggable TMSM events.
TRAILINGLINESThis control enables users to specify the number of blank lines to be printed after the Field Mode response from data-returning SQL statements.
TRANSLATECTRLSTOSPACESThis control enables users to specify whether BTEQ should translate the control-range characters for Field Mode columnar report’s data rows (non-title) bound for stdout or an EXPORT REPORT file.
TRIMTRAILINGSPACESThis control enables users to specify whether to trim trailing spaces from Field Mode response lines.
TSOSubmits a command to the z/OS interactive TSO environment.
UNDERLINEThis control enables users to specify whether one line of dash characters, which spans all report columns, is to be printed whenever the value of the indicated column changes.
WIDTHSpecifies the printing limit for each line in a report.

Teradata BTEQ Examples using above Commands

Following BTEQ scripts imports the data from flat file and load into target table.

.SET SESSION 10;
.SET QUIET ON
.PACK 200;
.LOGON 192.168.1.19/dbc, dbc;
.import vartext '|' FILE = /home/tpcdsData/catalog_page.dat;
.REPEAT *
 USING (
cp_catalog_page_sk VARCHAR(2000),  
cp_catalog_page_id VARCHAR(2000),  
cp_start_date_sk VARCHAR(2000), 
cp_end_date_sk VARCHAR(2000), 
cp_department VARCHAR(2000), 
cp_catalog_number VARCHAR(2000), 
cp_catalog_page_number VARCHAR(2000), 
cp_description VARCHAR(2000), 
cp_type VARCHAR(2000)
     )
INSERT INTO tpcds.catalog_page
    VALUES (
:cp_catalog_page_sk, 
:cp_catalog_page_id, 
:cp_start_date_sk,
:cp_end_date_sk,
:cp_department,
:cp_catalog_number,
:cp_catalog_page_number,
:cp_description,
:cp_type
    );
.QUIT
.LOGOFF

Related Articles,

Hope it helps 🙂