How to export the table to a file using BTEQ script in Teradata

Contents

EXPORT command in Teradata

Export command is used to store the database information that returned by SQL Select statement in a file. We need to specify the path of the file and its format while export the results from the table in Teradata

Syntax of Export command

.EXPORT FILE = <output file path>;

BTEQ script to export the table to a file

.LOGON tdpid/userid,password
.EXPORT FILE = C:\Users\revisit_class\output.txt;
.SET SEPARATOR '|'
SEL * FROM Banking_DB.EMPLOYEE;
.LOGOFF
.EXIT

.LOGON – It is command, which is used to log on to a Teradata Database from BTEQ. We need to specify the teradata server details(tdpid) ,username and password to execute this script.

.EXPORT FILE – It exports the results of the select query into a given file.

.SET SEPARATOR – It inserts the specified string between the columns. Each column content will be separated by ‘|’

Select query – We need to specify the select query to extract the data from the Employee table in Banking_DB. The output will be written into the output.txt file.

.LOGOFF – Ends the current Teradata Database sessions without exiting BTEQ.

.EXIT – Ends the current Terdata Database sessions and exits BTEQ.

We can run this BTEQ script using shell script. Please click the link for more details. Once we have run the BTEQ , the data will be exported into the text file as below

Output

Employee_Id|Department_Id|Employee_Name       | Join_Date|Mobile_Number
----------- ------------- -------------------- ---------- -------------
        120|         4892|Michael             |2019/02/23|    982322924
        123|         5653|Peter               |2019/01/28|    383234734
        127|         2726|Chris               |2019/01/28|    372328394
        128|         3782|John                |2019/01/28|    473234794
        130|         4892|Harsh               |2019/02/22|    892119322

Recommended Articles

Import Excel data into Teradata table