Sunteți pe pagina 1din 5

Basic Teradata Learnings


RETAIL & DISTRIBUTION – Business Intelligence

Ajay Shenai

Internal Use
Basic Teradata FAQ’s

Basic Teradata FAQ’s:

Question 1:
What is EXPLAIN in Teradata and how does it work?
Answer 1:
The EXPLAIN facility is a Teradata extension that provides you with an “ENGLISH translation
of the steps chosen by the optimizer to execute an SQL statement.
EXPLAIN Select last_name, first_name FROM employees;

The EXPLAIN facility is used to analyze all joins and complex queries.

Question 2:
What is the CAST function and what are its limitations?
Answer 2:
Cast converts an expression of a given data type to a different data type or the same data
type with a different format. However, there are certain limitations during conversion. Cast
does not convert the following data type pairs:
1. Numeric to character, if the server character set is GRAPHIC.
2. Character expressions having different server character sets.
3. BYTE to any data type other than BYTE.
4. Any data type other than BYTE to BYTE.

Question 3:
How do I trim trailing special character in a String?
Answer 3:
Lets us consider the following string ’5001*5002*5031*’, the last character of this string needs
to be removed and can be handled as follows.

E.g. TRIM (TRAILING ‘*’ FROM (’5001*5002*5031*’) AS Corrected_String

Question 4:
How does timestamp subtraction take place in Teradata?
Answer 4:
This scenario occurs only during the inactivation of a record i.e. when SCD (Slowly Changing
Dimension) logic needs to be implemented. Example:
‘Eff_End_Dt - INTERVAL '00:00.001000' MINUTE TO SECOND’
Where Eff_End_Dt must have Timestamp as its data type.

Internal Use 2
Basic Teradata FAQ’s

Here it is ‘MINUTE TO SECOND’ because we want the inactivation to be done till the
millisecond level. This can also be changed as per the requirement and also the INTERVAL

Question 5:
What is optimization and performance tuning and how does it really work in practical
Answer 5:
Performance tuning and optimization of a query involves collecting statistics on join columns,
avoiding cross product join, selection of appropriate primary indexes and using secondary
indexes. Avoiding the usage of a NUSI (Non Unique Secondary Index) also helps in
optimization and performance tuning.

Question 6:
How Teradata makes sure that there are no duplicate rows being inserted when the
concerned table is a SET table?
Answer 6:
Teradata will redirect the new inserted rows as per its PI (Primary Index) to the target AMP
(on the basis of its row hash value), and if it finds the same row hash value in that AMP then it
starts comparing the whole row, and finds out if it is duplicate.
If the row is a duplicate, then it is skipped without any error being invoked.

Question 7:
What is Basic Teradata Query Language (BTEQ)?
Answer 7:

BTEQ’s are used for importing, exporting and reporting of data from teradata tables.
A BTEQ allows us to write SQL statements along with BTEQ commands.

A BTEQ command starts with a (.) dot and can be terminated by using a semi-colon (;),
although it is not mandatory to use a semi-colon (;). A SQL statement doesn’t start with a dot
(.), but a semi-colon (;) is compulsory to terminate the SQL statement.

A BTEQ assumes anything written without a dot as a SQL statement and requires a (;) to
terminate it.

Question 8:
What is Indexing?
Answer 8:
Indexing is a way to physically re-organize the rows in a table to enable frequently used
queries to run faster.
An index can be used as a pointer to a large table. It helps to locate the required row quickly
and then return it back to the user.

Internal Use 3
Basic Teradata FAQ’s

Question 9:
How can I execute a parameterized macro?
Answer 9:
The following is an example of a parameterized macro:
‘EXEC testing (10,’A’);’
Where testing is the macro being called and (10,’A’) are input parameters to the

Question 10:
What information about the specified table is provided by the HELP TABLE
Answer 10:
The following information is generated while executing the HELP TABLE statement:

- Column name
- Data type
- Comments.

Question 11:
Which request in ANSI mode, is equivalent to DELETE {table_name} in Teradata
Answer 11:

The following is the equivalent for a Teradata request:

‘DELETE FROM {table_name}; COMMIT;’

Question 12:
What is equivalent to Teradata’s MINUS operator in ANSI Mode?
Answer 12:
“EXCEPT” is equivalent to Teradata’s MINUS operator in ANSI Mode.

Internal Use 4
Basic Teradata FAQ’s

Question 13:
The position where a substring begins within a string is determined by which
Teradata SQL function?
Answer 13:
“INDEX” is the Teradata SQL function.

Question 14:
In a string expression of LIKE operator, which symbols act as wildcards?
Answer 14:

The following symbols act as wildcards:

_ (underscore) – this is used to signify the presence of one character
% (percentage) – this is used to signify none or one or more than one character.

Internal Use 5