Professional Documents
Culture Documents
Teradata SQLReference
Teradata SQLReference
Teradata SQLReference
INTERVAL YEAR(n)
INTERVAL MONTH(n)
INTERVAL DAY(n)
INTERVAL HOUR(n)
INTERVAL MINUTE(n)
The following table is a chart of all the ANSI Standard Data Types that Teradata supports.
Data Type Description Data Value Range
INTEGER Signed whole number -2,147,483,648 to 2,147,483,647
SMALLINT Signed smaller whole number -32,768 to 32,767
DECIMAL (X,Y) Signed decimal number 18 digits on Largest value DEC(18,0)
Where: X=1 thru 18, either side of the decimal point Smallest value DEC(18,18)
total number of digits in
the number
And Y=0 thru 18 digits
to the right of the
decimal
NUMERIC (X,Y) Synonym for DECIMAL Same as DECIMAL
Same as DECIMAL
FLOAT Floating Point Format (IEEE) <value>×10307 to <value>×10-308
REAL Stored internally as FLOAT
PRECISION Stored internally as FLOAT
DOUBLE PRECISION Stored internally as FLOAT
CHARACTER (X) Fixed length character string, 1 byte of 1 to 64,000 characters long,
CHAR (X) storage per character, pads to length with space
Teradata also has its own data types that are acknowledged as Teradata Extensions:
Data Type Description Data Value Range
BYTEINT Signed whole number -128 to 127
BYTE (X) Binary 1 to 64,000 bytes
Where: X=1 thru
64000
VARBYTE (X) Variable length binary 1 to 64,000 bytes
Where: X=1 thru
64000
Data Type Description Data Value Range
LONG VARCHAR Variable length string 64,000 characters (maximum data length) The
system only stores the characters provided, not
trailing spaces.)
GRAPHIC (X) Fixed length string of 16-bit 1 to 32,000 KANJI characters
Where: X=1 thru bytes (2 bytes per character)
32000
VARGRAPHIC (X) Variable length string of 16- 1 to 32,000 characters as a maximum. The
Where: X=1 thru bit bytes system only stores characters provided.
32000
Format Symbols
Formatting symbols are very powerful. These symbols allow the user to control the way data can be
inserted into a row and displayed in the result set. It provides for more predictable result sets.
Hint - Be sure to keep in mind that the ODBC will ignore formatting, unless you trick it.
Man To see true formatting, the user should use BTEQ.
In addition to have the ability to format Numeric and Character Data Types, a user may also format Dates.
Show: Will show the internal sql command (Like sp_helptext in SQL Server.)
Explain: It will show the set of steps executed inside for a command.
Ex: EXPLAIN
SELECT last_name, first_name
FROM Employee_Table
WHERE Salary > 45000;
Moves the scope of the user from one database to <Database Name>. This command can eliminate the
need to qualify a table in a certain database.
Account
Returns the account number for the current user you are logged in as.
Select ACCOUNT;
This command displays the database that the user is currently located.
Select DATABASE;
SESSION
Data Conversions
CAST
1. select cast(eno as char(10)) from empmast
CASESPECIFIC:
NOT CASESPECIFIC:
Aggregation Functions
“Having” is used with derived fields “where” is used with the existing db filed.
Sub Query…:
select deptno,count(sal) count_basic,sum(sal) sum_basic,avg(sal) Avg_Basic
from Memp
where deptno in (select distinct deptno from Mdept)
group by deptno;
ANY:
EXISTS:
SELECT Customer_Name
FROM Customer_Table AS CUST
WHERE EXISTS
(SELECT * FROM Order_Table AS OT
WHERE CUST.Customer_Number =
OT.Customer_Number) ;
NOT EXISTS:
SELECT Course_Name
FROM Course_Table AS Course
WHERE NOT EXISTS
(SELECT * FROM Student_Course_Table AS STU
WHERE COURSE.Course_Id = STU.Course_Id) ;
Correlated Subquery:
JOINS
select e.empno,e.ename,e.job,e.deptno,d.loc
from Memp e,Mdept d
where e.deptno=d.deptno