You are on page 1of 11

Teradata Objects Naming Conversions Names are composed of following characters A-Z (Upper Or Lower case) 0-9 #, $, _ Names

ames are limited to 30 characters Names should not begin with a numeric value

Teradata SQL Assistant It is GUI data discovery tool used to retrieve data from any ODBC-compliant database server. Teradata Case sensitivity Teradata is case insensitive on literals. By default capital A equals small a. Set the database to ANSI mode to be case sensitive or declare the column as CASE SPECIFIC. NULL order In Teradata, while ordering the data in ascending, NULL comes first, and in descending, comes last. This is opposite to Oracle NULL ordering Operator Precedence

Of dame level of precedence, the execution will be from Left to Right Built-in Functions

Also DATE, TIME, CURRENT_DATE, CURRENT_TIME, CURRENT_TIMESTAMP are available. Note that there is no dual table and select with built-in function will work Ok (Exampe SELECT DATE; will give date as output)

Data types CHAR(n) - Fixed Character, left justified, right padded with space to fill the length, trailing blanks are not considered in character string comparison VARCHAR(n) - Variable length and space counts as valid character CLOB (n [K|M|G]) - character large objects of Kilobytes, Megabytes and Gigabytes Where n is the number of character allowed to store on the column, and it is the amount of byte required to store the data. INTEGER DATATYPE BYTEINT SMALLINT INTEGER BIGINT CHAR NEED TO DISPLAY 4 5 11 20

Standards Teradata Extension ANSI Standard ANSI Standard ANSI Standard

RANGE -128 to + 127 -32,768 to +32,767 -2,147,486,648 to +2,147,483,647 -/+ 9,233,372,036,854,755,807

DECIMAL (m,n) or NUMBERIC (M,N) , where m - is total number of digits that the data type will support and n is howmany of those defined by m are fractional Value of m digit 1 or 2 digit 3 or 4 digit 5 to 9 digit 10 to 18 digit 18 to 38 Bytes Required 1 2 4 8 16

FLOAT - can be used to represent data values that are beyond the ranges of the other numeric data types. However they have only 15 digits of precision compared to integer and decimal data types. The data of the 2 * 10^307 to 2 * 10^308 range can be accommodated using FLOAT data type. DATE is a special kind (stored internally) of integer data type in Teradata. The integer representation of date is either YYYYMMDD or YYMMDD. The character representation of date is -> DATEYYYY-MM-DD

Arithmetic Operators

Note: 8.00/3 yields 2.67 and 9/4 yields 2. The remainder is not displayed because the representation of 9 and 4 are not decimal

Note: Exponential result in float data type.

Arithmetic Functions

Date Arithmetic Operand1 DATE DATE'YYYY-MM-DD' CURRENT_DATE CURRENT_DATE Operator + + Operand2 Number Number DATE'YYYY-MM-DD' date column Yields DATE DATE INTEGER INTEGER

Data Type Conversion 1) CAST function (ANSI standard) Syntax: CAST (expression AS data type) 2) Teradata Extension expression (data type)

Need to take notes here in fresh mind Decimal Rounding 1) Biased mode: If decimal digits are 5 and above, then round up else round down 2) Unbiased mode: If decimal is greater than 5 then round up, less than 5 round down, equals 5 then round to the even numbered digit There is no option of the developer to select the rounding mode. It is based on the DBSControl Record, which is maintained by the administrator FORMAT

Example: SELECT CAST ( salary_amount (FORMAT $$$$,$$$,$$9.99) AS CHAR(15) ) From employees;

Date Format

Functions

1) 2) 3) 4) 5) 6)

Upper Lower Character_length TRIM ( [ LEADING|BOTH|TRAILING ] [trim_characters] FROM expression ) Position ( expression1 in expression2) Substring (expression1 FROM n1 [For n2] )

7) LIKE same as Oracle % and _. Escape meta character can be anything chosen by the user

8) LIKE ANY Use it while searching for one TRUE condition on the multiple pattern search. Syntax: expression LIKE ANY (pattern_search1, pattern_search2) Equivalent: expression LIKE pattern_search1 OR expression LIKE pattern_search2 9) LIKE SOME LIKE SOME is same as LIKE ANY 10) LIKE ALL Use it while searching for all TRUE condition on the multiple pattern search. Syntax: expression LIKE ALL (pattern_search1, pattern_search2) Equivalent: expression LIKE pattern_search1 AND expression LIKE pattern_search2 11) CASESPECIFIC -> will yield a string for comparison that are case specific Syntax: expression ( CASESPECIFIC| CS ) 12) EXTRACT used to extract portions of date or time value. They always return an integer value Syntax: EXTRACT (YEAR|MONTH|DAY FROM DATEYYYY-MM-DD) Syntax: EXTRACT (HOUR|MINUTE|SECOND FROM TIMEHOUR:MINUTE:SECOND) 13) ADD MONTHS creates a new date by adding integer number of months Syntax: ADD_MONTHS (DATEYYYY-MM-DD, integer-expression) 14) TYPE Returns the data type of the expression. The syntax is TYPE(expression) 15) DEFAULT Returns the default value of the column 16) String Concatenation (||) -> While concatenating multiple stings, if at lease any one value is NULL, the output is null. It is not true in Oracle. If at least one value is not null, the output will be not null 17) NULLIF (Exp1,Exp2) If exp1 is equal to exp2, then returns NULL else exp1 18) COALESCE (expr1, expr2,...exprn) - returns the first NOT NULL value. (pronunciation co-a-lec) SET OPERATION SELECT statement connected by SET operators can include all of the normal clause options for SELECT except the WITH clause EXCEPT is used in Teradata instead of MINUS ORDER BY if used should be in the end with column positions The data type of the first SQL is considered by Teradata. For example if column in 10 length in first SQL and it is 20 length in second SQL, then the first SQL length is taken and the data is truncated for extra length in second SQL. (Note in ANSI mode, this would result in a error)

Note: The above statement is true for character data type. In integers, it may result in numeric overflow ALL operator can be used with UNION, EXCEPT and INTERSECT to obtain a result set that dont eliminate the duplicates The default data type for NULL is integer. It can be changed as TYPE(NULL) or NULL (CHAR(30))

GROUP Functions GROUP BY can reference a column by name or positional value GROUP BY can reference alias name in GROUP BY and HAVING HAVING Used to have filer condition on aggregates. It is also possible to have a nonaggregating filer condition in having clause, but it will yield a bas performance, since the having clause is executed over the result retrieved using WHERE clause

Order of Execution

CASE Statement CASE column WHEN value1 THEN return1 WHEN value2 THEN return2 [ELSE condition3 | NULL] END

Cannot have SELECT statement value or condition space CASE WHEN condition1 THEN return1 WHEN condition2 THEN return2 [ELSE condition3 | NULL] END

Table Creation

SET -> Teradata mode, Not Case specific, dont allow duplicates MULTISET -> ANSI mode, Case Specific, Allow duplicates

You might also like