You are on page 1of 4

Checklist for Teradata SQLs

18/08/2010

EIS / SP
Jagadeesan. M
jagadeesan.m@tcs.com

TCS Public

Following are some of the Checklist needs to be followed while


using Teradata:
1. The Oracle functions like TO_CHAR, LPAD, RPAD are not supported in Teradata.
Thus this can be achieved by parsing the data programmatic-ally.

2. Usage of Teradata keywords in queries as an alias name or column name should be


strictly avoided.
Sample keywords Type, Zone, Result, position, queue.
Check the following URL for complete list of keywords:
http://www.teradataforum.com/l030103a.htm

3. There should not be any SELECT query inside a SELECT clause of a query. Following
query format should be avoided:
SELECT coln1,
(SELECT MAX(bal_amt) from bal_history),
coln3 FROM user_credit_account;

4. While performing ORDER BY for a query having JOIN conditions, use the column
names prefixed with table alias names (avoid using column alias name alone).
Eg: SELECT e.emp_id, e.emp_name, m.emp_name FROM
proj_emp e, proj_manger m WHERE e.mgr_id = m.emp_id
ORDER BY e.emp_name;
// avoid ORDER BY 2;

5. There should not be any SELECT query immediately after the FROM clause of
parent/main query.

6. Check whether database schema names are appended prior to all table names
used in the queries.(eg: SchemaName.TableName)

TCS Public

7. Most data, varchar as well as numeric data present in Teradata database were
found to contain blank spaces appended to them. Check whether TRIM function is
used while comparing varchar column values in the WHERE clause of a query.

8. If your query contains a UNION, MINUS, or INTERSECT operator you can not
reference the column(s) by name in your ORDER BY clause. Only the column
number can be used in the ORDER BY clause.

9. The pseudo column ROWNUM is not supported by Teradata. So, do not use
rownum. The Teradata equivalent for this is:
Oracle:
SELECT * FROM salary WHERE ROWNUM <= 2;
Teradata:
SELECT TOP 2 * FROM salary

10. The dual table is not present in Teradata. So, do not use dual table in queries. But
the same functionality can be derived by the following code. Before that just to
remind that the Dual table in Oracle is used for intermediate calculations, like
selecting a date and calculating something. In Teradata it is done without the use
of any such table.
Oracle:
SELECT SYSDATE FROM DUAL;
Teradata:
SELECT DATE

11. Check for proper spaces between keywords in queries.

12. Check whether varchar columns in WHERE clauses of queries are separated by
single quotes.

13. Date field in the DB can be retrieved only by using getDate method in java, where
as in oracle this field can be retrieved by using both getDate and getTimestamp
method.

TCS Public

14. Date fields can be retrieved in the format 'yyyy/mm/dd' in teradata, so we should
not tried to substring this value beyond the length of 10. (i.e) date values retrieved
using getDate() method can be substringed only up to this limit dt.subString(0,
10).

15. NULL in the select list of an UNION query has to be type casted in Teradata, for eg,
the query like this:
SELECT coln1, coln2 from table1
UNION
SELECT coln2, null from table2
is not allowed in Teradata, suppose if coln2 of table1 has CHAR(8) datatype, then
the above query has to be rewritten as:
SELECT coln1, coln2 from table1
UNION
SELECT coln2, CAST(null AS CHAR(8)) from table2

16. There is no CLOB or BLOB datatype in Teradata.


The Teradata VARBYTE data type can contain only the specified length (1 to 64000)
of a DB2/Oracle BLOB data type.
The Teradata VARCHAR data type can contain only the specified length (1 to
64000) of a DB2/Oracle CLOB data type.

17. To sort the column data based on case sensitivity, which displays the UPPER CASE
data first of same order first and then the lower case.
We can do it either of the two way:
1. During table definition
CREATE VOLATILE TABLE MyTest2
(ColA SMALLINT NOT NULL,
ColB VARCHAR(5) NOT NULL NOT
CASESPECIFIC) PRIMARY INDEX (ColA);
2. While querying
ORDER BY ColB (CASESPECIFIC);

TCS Public