BTEQ stands for Basic Teradata Query. It is Teradata’s command-line utility for running SQL interactively or from batch scripts. Use BTEQ commands such as .LOGON, .EXPORT and .IMPORT to control connections and data transfer, and SQL statements to query or change database data.
Watch: error checks in BTEQ scripts
This video shows the script side of this article in action: dot commands next to SQL, why a failed request does not stop a BTEQ script, how .IF ERRORCODE and .QUIT hand the scheduler a reliable return code, and how .IMPORT with .REPEAT loads a file.
This guide covers when to use BTEQ, common commands, importing and exporting data, and running a script. For a graphical Windows client, see Teradata SQL Assistant.
ETL-Tools versus BTEQ
BTEQ is useful for repeatable SQL scripts, while TPT provides specialized data-movement operators. ETL platforms may add lineage, orchestration, connectors and governance. Choose from the requirements and measured operational costs; mixing tools does not inherently remove their benefits.
Frequently Asked Questions about Teradata BTEQ
How is data imported and exported with BTEQ?
BTEQ imports and exports data using the selected record or text format. For large bulk transfers, compare it with the appropriate TPT operators. Performance depends on format, request size, sessions and workload.
Can Teradata BTEQ perform loops?
BTEQ supports repeated execution with .REPEAT and conditional loops using .LABEL and .GOTO. Design a terminating condition and handle errors explicitly.
Can I define my variables in BTEQ?
Variables cannot be defined. A common workaround is to use Linux parameters in the BTEQ scripts and replace them with a wrapper script.
What types of conditional logic does BTEQ handle?
We can use the “. GOTO” command with which we can jump to a specific label (indicated by “.LABEL“).
Which methods for conditional statements and branches exist in BTEQ?
There are the conditional statements available like in most procedural languages:
IF, THEN, ELSE, ENDIF.
Can I determine how many rows are affected by an INSERT, UPDATE, or DELETE?
ACTIVITYCOUNT reports the activity count for the preceding request. INSERTCOUNT and UPDATECOUNT have statement-specific meaning, including MERGE outcomes; check the BTEQ reference for the statement and release instead of treating UPDATECOUNT as a universal counter.
How is error handling implemented in a Teradata BTEQ script?
Check ERRORCODE immediately after the statement. For failure: .IF ERRORCODE <> 0 THEN .QUIT 8. For success: .IF ERRORCODE = 0 THEN .GOTO NextStep. Define the destination with .LABEL NextStep.
Is there a possibility of executing Linux commands from BTEQ?
You can execute the command “.OS <linux_command>”.
Can I run another BTEQ from within BTEQ?
Use .RUN FILE = script.bteq to read commands from a file in the current BTEQ session. It does not by itself launch a separate BTEQ process or logon.
Teradata BTEQ Export
BTEQ enables exporting of data in various formats, including four of the most significant ones:
Get the complete Teradata tuning book, free
Teradata Query Performance Tuning: The DWHPro Guide
By Roland Wenzlofsky & Artemios Vogiatzis
206 pages on statistics and demographics, access paths and indexes, query execution plans, and joins. Get the full PDF and practical Teradata updates from DWHPro.
Confirm your email to receive your download link. Privacy policy. Unsubscribe in any newsletter.
About the free book- EXPORT DATA:
Exports data in record mode.
You can use this format to exchange data between Fastload, Fast Export, Multiload, and BTEQ. - EXPORT REPORT:
The data is exported as a report in a readable format and contains the columns as headers. This is the default mode. - EXPORT INDICDATA:
NULL values are marked in this format - EXPORT DIF:
Creates a file in DIF (Data Interchange Format) format, which can be read on any Windows system.
A Teradata BTEQ Export Example
BTEQ EXPORT DATA writes binary records, not a readable text or CSV file. The import field definitions must match that record layout.
.LOGON SYSTEM1/DWHPRO,DWHPRO_PWD
.EXPORT DATA FILE = /tmp/dwhpro.dat
SELECT * FROM Customer;
.EXPORT RESET
.LOGOFF
.QUIT
The BTEQ export function writes the “Customer” table in report mode to a user-readable text file with column headers.
.LOGON SYSTEM1/DWHPRO,DWHPRO_PWD
.EXPORT REPORT FILE = /tmp/dwhpro.dat
SELECT * FROM Customer;
.EXPORT RESET
.LOGOFF
.QUIT
The BTEQ export function writes the Customer table in report mode to a text file while utilizing the TITLE command to remove column headers:
.LOGON SYSTEM1/DWHPRO,DWHPRO_PWD
.SET TITLEDASHES OFF
.EXPORT REPORT FILE = /tmp/dwhpro.dat
SELECT FirstName (TITLE ''), LastName (TITLE '')
FROM Customer;
.EXPORT RESET
.LOGOFF
.QUIT
The concatenation below is only a delimiter demonstration for non-NULL fields without commas, quotes or newlines. It is not a general CSV exporter. Use a CSV-aware client or writer for arbitrary text, with explicit quoting, escaping and NULL conventions.
.LOGON SYSTEM1/DWHPRO,DWHPRO_PWD
.SET TITLEDASHES OFF
.EXPORT REPORT FILE = /tmp/dwhpro.dat
SELECT FirstName|| ',' || LastName (TITLE '')
FROM Customer;
.EXPORT RESET
.LOGOFF
.QUIT
A Teradata BTEQ Import Example
A file in record mode can be imported via BTEQ. The command “REPEAT” directs the reading of all lines.
.LOGON SYSTEM1/DWHPRO,DWHPRO_PWD
.IMPORT DATA FILE = /tmp/dwhpro.dat
.REPEAT *
USING (FirstName VARCHAR(200), LastName VARCHAR(200))
INSERT INTO Customer VALUES (:FirstName,:LastName);
.LOGOFF
.QUIT
This VARTEXT example expects simple comma-delimited fields. Configure the delimiter explicitly. General quoted CSV, embedded delimiters/newlines and NULL representations require a compatible parser and agreed file format.
.LOGON SYSTEM1/DWHPRO,DWHPRO_PWD
.IMPORT VARTEXT ',' FILE = /tmp/dwhpro.dat
.REPEAT *
USING (FirstName VARCHAR(200), LastName VARCHAR(200))
INSERT INTO Customer VALUES (:FirstName,:LastName);
.LOGOFF
.QUIT
Teradata BTEQ Sessions
Multiple sessions are analogous to multiple users with identical credentials. Each session is associated with the same user and has the ability to execute one or more consecutive transactions.
.SET SESSIONS 100
.LOGON SYSTEM1/DWHPRO,DWHPRO_PWD
<...>
.LOGOFF
Utilizing multiple sessions can enhance the efficiency of a BTEQ script.
Multiple sessions can help suitable import workloads, especially short requests, but can also add overhead and contention. Choose session counts from measurements; PI/USI access is not a universal syntax requirement.
For additional information, please refer to the following article.
Teradata BTEQ Fast Path Insert
A single multi-statement request can enable eligible empty-target INSERT SELECT optimizations. The target state, table features and release restrictions still matter; matching primary indexes and semicolon placement alone do not guarantee a fast path.

Place a semicolon at the beginning of the lines (“;INSERT INTO”) as shown in the following example
.SET SESSIONS 100
.LOGON SYSTEM1/DWHPRO,DWHPRO_PWD
INSERT INTO CUSTOMER SELECT * FROM Customer1
;INSERT INTO CUSTOMER SELECT * FROM Customer2;
.LOGOFF
The following historical illustration contrasts two execution paths. It does not establish that punctuation or differing primary indexes alone determines the plan.

BTEQ FAQ
What is BTEQ in Teradata?
BTEQ, or Basic Teradata Query, is a command-driven utility that allows users to interact with Teradata databases. It is a popular tool for querying, importing, and exporting data within the Teradata environment. BTEQ is designed for batch processing, making it a powerful and flexible tool for executing SQL queries and scripts, generating reports, and automating tasks across different platforms.
What is the difference between Teradata SQL Assistant and BTEQ?
Teradata SQL Assistant and BTEQ are tools for interacting with Teradata databases, but they have distinct features and different purposes. Teradata SQL Assistant is a graphical user interface (GUI) that allows users to write, edit, and execute SQL queries and import and export data. It is primarily designed for ease of use and is more suitable for users who prefer a visual approach to database management.
BTEQ, on the other hand, is a command-line utility that is more suitable for batch processing and automation. It is a more powerful and flexible tool for advanced users who are comfortable working with command-line interfaces. While Teradata SQL Assistant offers a user-friendly experience, BTEQ provides greater control and customization options for executing SQL queries and scripts.
What is a BTEQ command?
A BTEQ command is a text-based instruction to perform a specific action or operation within the BTEQ environment. BTEQ commands can be divided into two categories: SQL commands and BTEQ-specific commands. SQL commands are standard SQL statements that can be executed in BTEQ, such as SELECT, INSERT, UPDATE, and DELETE. BTEQ-specific commands are unique to the BTEQ utility and provide additional functionality, such as controlling the formatting of query results, managing error handling, and setting environment variables.
Some examples of BTEQ-specific commands include:
.LOGON: Used to log on to a Teradata database.LOGOFF: Used to log off from a Teradata database.SET: Used to configure BTEQ settings, such as error handling and output formatting.EXPORT: Used to export query results to a file
How to run BTEQ in Teradata?
To run BTEQ in Teradata, follow these steps:
- Open a command prompt or terminal window on your computer.
- Start the client by entering
bteq. At its prompt, enter.LOGON your_database/your_usernameand supply the password when prompted. Use the authentication method configured for your environment; do not put passwords in shell command history. - After successfully logging in, you can start executing SQL commands and BTEQ-specific commands.
- To execute a command, type the command and press Enter.
- To execute multiple commands, you can create a script file containing the commands and then run the script in BTEQ using the command:
bteq < script_filename - To exit BTEQ, type
.QUITand press Enter.
Please see the Teradata BTEQ documentation linked below:
Two more tools around BTEQ: what a macro replaces in a BTEQ script and a web-based alternative to Teradata Studio.
For the Windows desktop workflow, see connecting and exporting CSV files with Teradata SQL Assistant. Use the client that fits the task: a desktop answer set and a repeatable batch script have different operational requirements.
Building or improving a data pipeline?
Discuss ingestion, transformations, orchestration, quality checks and operational handover.
Get the complete Teradata tuning book, free
Teradata Query Performance Tuning: The DWHPro Guide
By Roland Wenzlofsky & Artemios Vogiatzis
206 pages on statistics and demographics, access paths and indexes, query execution plans, and joins. Get the full PDF and practical Teradata updates from DWHPro.
Confirm your email to receive your download link. Privacy policy. Unsubscribe in any newsletter.
About the free book