When loading data from an external file into a Teradata database, you can use the FastLoad utility. FastLoad is designed to quickly load large amounts of data into empty Teradata tables while minimizing the use of system resources. It's important to note that FastLoad performs best when loading into an empty table as it doesn't do duplicate row checking, nor can it load data into a table with secondary indexes or unique primary indexes.
Here's a basic outline of steps to create a FastLoad script:
-
Prepare your environment: Make sure you have access to the Teradata system, necessary permissions, and have installed Teradata Tools and Utilities on your client machine.
-
Prepare your input file: This should be the external file you want to load. Ensure its format is compatible with what you describe in the FastLoad script (e.g., delimited text).
-
Define your Teradata table: Make sure the table you are loading data into is empty and matches the structure of the data in your input file.
-
Write the FastLoad script: This script will include instructions for logging into your Teradata database, defining the file layout, and specifying the target table.
-
Execute the FastLoad script: Run the script using the command-line FastLoad utility.
Example FastLoad Script
The following is an example FastLoad script to load data from an external file named datafile.txt into a Teradata table named my_table. The table is assumed to have two columns: id and name.
LOGON mydbserver/myusername,mypassword;
DROP TABLE my_table;
DROP TABLE my_table_Error1;
DROP TABLE my_table_Error2;
CREATE TABLE my_table, NO FALLBACK (
id INTEGER,
name VARCHAR(100)
);
SET RECORD UNFORMATTED;
DEFINE
id (INTEGER),
name (VARCHAR(100))
FILE=datafile.txt;
SHOW;
BEGIN LOADING my_table
ERRORFILES my_table_Error1, my_table_Error2;
INSERT INTO my_table (:.id, :.name);
END LOADING;
LOGOFF;
Points to Consider:
- Customize the
LOGON line with your Teradata server, username, and password.
- Adjust the
CREATE TABLE statement according to your actual table schema.
- In the
DEFINE section, map out the fields in your input file to their corresponding Teradata table columns.
- Confirm the path to
datafile.txt is accurate or accessible by the FastLoad utility.
my_table_Error1 and my_table_Error2 are error tables that FastLoad uses to log errors encountered during the load process.
Running the FastLoad Script:
To run the FastLoad script, save it to a file (e.g., load_script.txt) and use the FastLoad command in your command-line interface as follows:
fastload < load_script.txt
Ensure you execute this command in an environment where the FastLoad utility is installed and accessible.
Additional Notes:
- FastLoad requires the target table to be empty. If you're loading into an existing table, make sure it's emptied beforehand.
- For comprehensive details, it's beneficial to refer to the FastLoad reference guide specific to your Teradata version, as commands and features might vary.