Sie sind auf Seite 1von 10

Why is BTEQ available on every Teradata system ever built?

Because theBatchTErad
ataQuery (BTEQ) tool was the original way that SQL was submitted to Teradata as
a means of getting an answer set in a desired format. This is the utility that I
used for training at Wal*Mart, AT&T, Anthem Blue Cross and Blue Shield, and Sou
thWestern Bell back in the early 1990's. BTEQ is often referred to as theBasicTE
radataQuery and is still used today and continues to be an effective tool.
Here is what is excellent about BTEQ:
?
BTEQ can be used to submit SQL in either a batch or interactive environment. Int
eractive users can submit SQL
and receive an answer set on the screen. Users can also submit BTEQ jobs from ba
tch scripts, have error
checking and conditional logic, and allow for the work to be done in the backgro
und.
?
BTEQ outputs a report format, where Queryman outputs data in a format more like
a spreadsheet. This allows BTEQ a great deal of flexibility in formatting data,
creating headings, and utilizing Teradata extensions, such as WITH and WITH BY t
hat Queryman has problems in handling.
?
BTEQ is often used to submit SQL, but is also an excellent tool for importing an
d exporting data.
oImporting Data: Data can be read from a file on either a mainframe or LAN attac
hed computer and used for
substitution directly into any Teradata SQL using the INSERT, UPDATE or DELETE s
tatements.
oExporting Data: Data can be written to either a mainframe or LAN attached compu
ter using a SELECT from
Teradata. You can also pick the format you desire ranging from data files to pri
nted reports to Excel formats.
There are other utilities that are faster than BTEQ for importing or exporting d
ata. We will talk about these in future
chapters, but BTEQ is still used for smaller jobs.
Logging on to BTEQ
Before you can use BTEQ, you must have user access rights to the client system a
nd privileges to the Teradata DBS.
Normal system access privileges include a userid and a password. Some systems ma
y also require additional user
identification codes depending on company standards and operational procedures.
Depending on the configuration of
your Teradata DBS, you may need to include an account identifier (acctid) and/or
a Teradata Director Program
Identifier (TDPID).
Using BTEQ to submit queries
Submitting SQL in BTEQ's Interactive Mode
Once you logon to Teradata through BTEQ, you are ready to run your queries. Tera
data knows the SQL is finished
when it finds a semi-colon, so don't forget to put one at the end of your query.
Below is an example of a Teradata table
to demonstrate BTEQ operations.
Employee_Table
Figure 2-1
BTEQ execution
Page 1 of 91
Teradata Utilities-Breaking the Barriers, First Edition
Figure 2-2
Submitting SQL in BTEQ's Batch Mode
On network-attached systems, BTEQ can also run in batch mode under UNIX (IBMAIX,
Hewlett-PackardHP-UX, NCRMP- RAS, SunSolaris), DOS, Macintosh, Microsoft Window
s and OS/2 operating systems. To submit a job in Batch mode do the following:
1. Invoke BTEQ
2. Type in the input file name
3. Type in the location and output file name.
The following example shows how to invoke BTEQ from a DOS command. In order for
this to work, the directory
called Program Files\NCR\Teradata Client\bin must be established in the search p
ath.
Figure 2-3
Notice that the BTEQ command is immediately followed by the <BatchScript.txt' to
tell BTEQ which file contains the
commands to execute. Then, the >Output.txt' names the file where the output messa
ges are written. Here is an
example of the contents of BatchScript.txt file.
BatchScript.txt File
Figure 2-4
The above illustration shows how BTEQ can be manually invoked from a command pro
mpt and displays how to
specify the name and location of the batch script file to be executed.
The previous examples show that when logging onto BTEQ in interactive mode, the
user actually types in a logon string and then Teradata will prompt for a passwo
rd. However, in batch mode, Teradata requires both a logon and password to be di
rectly stored as part of the script.
Since putting this sensitive information into a script is scary for security rea
sons, inserting the password directly into a
script that is to be processed in batch mode may not be a good idea. It is gener
ally recommended and a common
practice to store the logon and password in a separate file that that can be sec
ured. That way, it is not in the script for
anyone to see.
For example, the contents of a file called "mylogon.txt" might be:
.LOGON cdw/sql00,whynot.
Then, the script should contain the following command instead of a .LOGON, as sh
own below and again in the
following script: .RUN FILE=mylogon.txt
This command opens and reads the file. It then executes every record in the file
.
Page 2 of 91
Teradata Utilities-Breaking the Barriers, First Edition
Using BTEQ Conditional Logic
Below is a BTEQ batch script example. The initial steps of the script will estab
lish the logon, the database, and the
delete all the rows from the Employee_Table. If the table does not exist, the BT
EQ conditional logic will instruct
Teradata to create it. However, if the table already exists, then Teradata will
move forward and insert data.
Note
In script examples, the left panel contains BTEQ base commands and the right pan
el provides a
brief description of each command.
Figure 2-5
Using BTEQ to Export Data
BTEQ allows data to be exported directly from Teradata to a file on a mainframe
or network-attached computer. In addition, the BTEQ export function has several
export formats that a user can choose depending on the desired output. Generally
, users will export data to a flat file format that is composed of a variety of
characteristics. These characteristics include: field mode, indicator mode, or d
if mode. Below is an expanded explanation of the different mode options.
Format of the EXPORT command:
.EXPORT <mode> {FILE | DDNAME } = <filename> [, LIMIT=n]
Record Mode: (also called DATA mode): This is set by .EXPORT DATA. This will bri
ng data back as a flat file. Each
parcel will contain a complete record. Since it is not a report, there are no he
aders or white space between the data contained in each column and the data is w
ritten to the file (e.g., disk drive file) in native format. For example, this m
eans that INTEGER data is written as a 4-byte binary field. Therefore, it cannot
be read and understood using a normal text editor.
Field Mode (also called REPORT mode): This is set by .EXPORT REPORT. This is the
default mode for BTEQ and
brings the data back as if it was a standard SQL SELECT statement. The output of
this BTEQ export would return the
column headers for the fields, white space, expanded packed or binary data (for
humans to read) and can be
understood using a text editor.
Indicator Mode: This is set by .EXPORT INDICDATA. This mode writes the data in d
ata mode, but also provides host
operating systems with the means of recognizing missing or unknown data (NULL) f
ields. This is important if the data
is to be loaded into another Relational Database System (RDBMS).
The issue is that there is no standard character defined to represent either a n
umeric or character NULL. So, every system uses a zero for a numeric NULL and a
space or blank for a character NULL. If this data is simply loaded into another
RDBMS, it is no longer a NULL, but a zero or space.
To remedy this situation, INDICATA puts a bitmap at the front of every record wr
itten to the disk. This bitmap contains
one bit per field/column. When a Teradata column contains a NULL, the bit for th
at field is turned on by setting it to a
"1". Likewise, if the data is not NULL, the bit remains a zero. Therefore, the l
oading utility reads these bits as
indicators of NULL data and identifies the column(s) as NULL when data is loaded
back into the table, where
appropriate.
Page 3 of 91
Teradata Utilities-Breaking the Barriers, First Edition
Since both DATA and INDICDATA store each column on disk in native format with kn
own lengths and characteristics,
they are the fastest method of transferring data. However, it becomes imperative
that you be consistent. When it is
exported as DATA, it must be imported as DATA and the same is true for INDICDATA
.
Again, this internal processing is automatic and potentially important. Yet, on
a network-attached system, being
consistent is our only responsibility. However, on a mainframe system, you must
account for these bits when defining
the LRECL in the Job Control Language (JCL). Otherwise, your length is too short
and the job will end with an error.
To determine the correct length, the following information is important. As ment
ioned earlier, one bit is needed per field
output onto disk. However, computers allocate data in bytes, not bits. Therefore
, if one bit is needed a minimum of
eight (8 bits per byte) are allocated. Therefore, for every eight fields, the LR
ECL becomes 1 byte longer and must be
added. In other words, for nine columns selected, 2 bytes are added even though
only nine bits are needed.
With this being stated, there is one indicator bit per field selected. INDICDATA
mode gives the Host computer the
ability to allocate bits in the form of a byte. Therefore, if one bit is require
d by the host system, INDICDATA mode will
automatically allocate eight of them. This means that from one to eight columns
being referenced in the SELECT will
add one byte to the length of the record. When selecting nine to sixteen columns
, the output record will be two bytes
longer.
When executing on non-mainframe systems, the record length is automatically main
tained. However, when exporting
to a mainframe, the JCL (LRECL) must account for this addition length.
DIF Mode: Known as Data Interchange Format, which allows users to export data fr
om Teradata to be directly utilized
for spreadsheet applications like Excel, FoxPro and Lotus.
The optional limit is to tell BTEQ to stop returning rows after a specific numbe
r (n) of rows. This might be handy in a
test environment to stop BTEQ before the end of transferring rows to the file.
BTEQ EXPORT Example Using Record (DATA) Mode
The following is an example that displays how to utilize the export Record (DATA
) option. Notice the periods (.) at the
beginning some of script lines. A period starting a line indicates a BTEQ comman
d. If there is no period, then the
command is an SQL command.
When doing an export on a Mainframe or a network-attached (e.g., LAN) computer,
there is one primary difference in
the .EXPORT command. The difference is the following:
?
Mainframe syntax:
?
LAN syntax:
.EXPORT DATA DDNAME = data definition state name (JCL)
.EXPORT DATA FILE = actual file name
The following example uses a Record (DATA) Mode format. The output of the export
ed data will be a flat file.
Employee_Table
Figure 2-6
BTEQ EXPORT Example Using Field (Report) Mode
The following is an example that displays how to utilize the export Field (Repor
t) option. Notice the periods (.) at the
beginning some of script lines. A period starting a line indicates a BTEQ comman
d and needs no semi-colon.
Likewise, if there is no period, then the command is an SQL command and requires
a semi-colon.
Page 4 of 91
Teradata Utilities-Breaking the Barriers, First Edition
Figure 2-7
After this script has completed, the following report will be generated on disk.
Employee_No
Last_name
First_name
Salary
Dept_No
2000000
Jones
Squiggy
32800.50
?
1256349
Harrison
Herbert
54500.00
400
1333454
Smith
John
48000.00
200
1121334
Strickling
Cletus
54500.00
400
1324657
Coffing
Billy
41888.88
200
2341218
Reilly
William
36000.00
400
1232578
Chambers
Mandee
56177.50
100
1000234
Smythe
Richard
64300.00
10
2312225
Larkins
Loraine
40200.00
300
I remember when my mom and dad purchased my first Lego set. I was so excited abo
ut building my first space station
that I ripped the box open, and proceeded to follow the instructions to complete
the station. However, when I was
done, I was not satisfied with the design and decided to make changes. So I buil
t another space ship and constructed
another launching station. BTEQ export works in the same manner, as the basic EX
PORT knowledge is acquired, the
more we can build on that foundation.
With that being said, the following is an example that displays a more robust ex
ample of utilizing the Field (Report)
option. This example will export data in Field (Report) Mode format. The output
of the exported data will appear like a
standard output of a SQL SELECT statement. In addition, aliases and a title have
been added to the script.
Figure 2-8
After this script has been completed, the following report will be generated on
disk.
Page 5 of 91
Teradata Utilities
Download this Document for FreePrintMobileCollectionsReport Document
Report this document?
Please tell us reason(s) for reporting this document
Spam or junk
Porn adult content
Hateful or offensive
If you are the copyright owner of this document and want to report it, please fo
llow these directions to submit a copyright infringement notice.
Cancel
This is a private document. Question_small
Info and Rating
Reads:
10,241
Uploaded:
05/07/2009
Category:
Research>Internet & Technology
Rated:
(1 Rating)
teradata
coming
insert
fast load
ncr teradata
like
teradata utility
end
difference
loading data
(more tags)
teradata
coming
insert
fast load
ncr teradata
like
teradata utility
end
difference
loading data
use
status
syntax
(fewer)
Follow
Ranjan Patra
Sign Up for an Ad-Free Scribd
* Remove all ads.
Never see ads on Scribd again.
No Thanks
Share & Embed
More from this user
PreviousNext
1.
29 p.
91 p.
Recent Readcasters
Add a Comment
Spinner_trans_gray
Ads by Google
Print this document
High Quality
Open the downloaded document, and select print from the file menu (PDF reader re
quired).
Icon_archives_35x35
Scribd Archive > Charge to your Mobile Phone Bill
You Must be Logged in to Download a Document
Use your Facebook login and see what your friends are reading and sharing.
Other login options
Login with FacebookSpinner_mac_white
Signup
I don't have a Facebook account
email address (required)
create username (required)
password (required)
Send me the Scribd Newsletter, and occasional account related communicat
ions.
Privacy policy Spinner_mac_white
You will receive email notifications regarding your account activity. You can ma
nage these notifications in your account settings. We promise to respect your pr
ivacy.
Why Sign up?
Num_1 Discover and connect with people of similar interests.
Num_2 Publish your documents quickly and easily.
Num_3 Share your reading interests on Scribd and social sites.
Social-icons
Already have a Scribd account?
email address or username
password
Spinner_mac_white Trouble logging in?
Login Successful
Now bringing you back...
Spinner_large_mac_white
« Back to Login
Reset your password
Please enter your email address below to reset your password. We will send you a
n email with instructions on how to continue.
Email address:

You need to provide a login for this account as well.


Login:

Upload a Document
* About
* Press
* Blog
* Partners
* Branded Reader
* Web Stuff
* Scribd Store
* Support
* FAQ
* Developers / API
* Jobs
* Terms - General
* Copyright
* Privacy
* Follow Us!
* scribd.com/scribd
* twitter.com/scribd
* facebook.com/scribd
scribd. scribd. scribd. scribd. scribd. scribd. scribd. scribd. scribd. scribd.
Icon_download_35x35
Download this document
Icon_pdf_54x56
pdf

Icon_doc_54x56
doc

Icon_txt_54x56
txt
15041762-Teradata-Utilities.pdf - 2.7 MB
Readcast:
Icon_archives_35x35
The Scribd Archive
This document was uploaded by someone just like you and is now part of The Scrib
d Archive*. Give back to the community and gain 24 hours of download access by u
ploading something of your own.
Processing...
Queued: Uploading: You have uploaded: Upload failed:
Document URL:
This document is: PrivateThis document is: Public
Cancel Upload

Make it easier to find your new document!


Title:
Category:
Tags: (separate with commas)
Description:
Queued: Uploading: You have uploaded: Upload failed: successTestTest
Document URL:
This document is: PrivateThis document is: Public
Cancel Upload
Done!
Make it easier to find your new document!
Title:
Category:
Tags: (separate with commas)
Description:
Queued: Uploading: You have uploaded: Upload failed: successTestTest
Document URL:
This document is: PrivateThis document is: Public
Cancel Upload
Done!
Make it easier to find your new document!
Title:
Category:
Tags: (separate with commas)
Description:
Or_divider_550x7
Subscribe to The Scribd Archive and download as many documents as you'd like.
1 Month Pass
Most Popular
$9
1 Day Pass
$5
1 Year Pass
$59
Choose payment optionSecure_checkout
Pay with Credit Card
Pay with PayPal or Credit
Charge to your mobile phone bill
* The Scribd Archive is a collection of millions of documents, including researc
h reports, best-selling books, news source materials, and more. Read the Scribd
Archive FAQ for more information.
Icon_download_35x35
Thanks for uploading! Download this document as
Icon_pdf_54x56
pdf

Icon_doc_54x56
doc

Icon_txt_54x56
txt
15041762-Teradata-Utilities.pdf

Das könnte Ihnen auch gefallen