5
DATA TYPES Every column in a table has a name and data type. The data type tells Teradata how much physical storage to set aside for the column, as well as the form in which to store the data. Teradata data types fall into categories: binary, character, date, and numeric data. Char data There are two data types for holding character data: CHAR - has fixed-length character strings. VARCHAR - has variable-length character strings. In both cases, the maximum string length is 64,000 characters. String size is specified in parentheses after the keyword CHAR or VARCHAR as in CHAR(20) or VARCHAR(20). In the case of CHAR, if you insert a character string less than the specified size (20 in the above example), the system will append and store trailing blanks as needed to expand the string to the specified length. The size specified on a VARCHAR field represents a maximum length. The system will not pad the contents with trailing blanks. (It will use two extra bytes to store the length internally) Example: Create table employee ( emp_id int, emp_no int, first_name char(20), last_name varchar(20) emp_add varchar (50),

Data Types

Embed Size (px)

DESCRIPTION

Data types in Tera Data

Citation preview

Page 1: Data Types

DATA TYPES

Every column in a table has a name and data type. The data type tells Teradata how much physical storage to set aside for the column, as well as the form in which to store the data. Teradata data types fall into categories: binary, character, date, and numeric data.

Char data

There are two data types for holding character data:

CHAR - has fixed-length character strings. VARCHAR - has variable-length character strings.

In both cases, the maximum string length is 64,000 characters. String size is specified in parentheses after the keyword CHAR or VARCHAR as in CHAR(20) or VARCHAR(20).

In the case of CHAR, if you insert a character string less than the specified size (20 in the above example), the system will append and store trailing blanks as needed to expand the string to the specified length.

The size specified on a VARCHAR field represents a maximum length. The system will not pad the contents with trailing blanks. (It will use two extra bytes to store the length internally)

Example:

Create table employee

( emp_id int,

emp_no int,

first_name char(20),

last_name varchar(20)

emp_add varchar (50),

dob date format (dd-mm-yyyy)

);

In this query we give firstname as hari,Actually it needs only 4 bytes.But the char datatype uses all 20 bytes.In the sense varchar we give the name it occupies only 4 bytes. VARCHAR makes more efficient use of the space, because it does not pad values with trailing blanks.

Page 2: Data Types

LONG VARCHAR is equivalent to a maximum VARCHAR

BYTE DATA

Teradata supports two data types for holding binary data:

BYTE. VARBYTE.

BYTE is for fixed length binary strings. Default: (1) Max: 64,000 bytes

VARBYTE is for variable length binary strings. These data types are used for storing binary objects such as digital images, executable objects, flat files,etc. Variable length Binary string Default: (1) Max: 64,000 bytes.

NUMERIC DATA

Data Type Description Examples

BYTEINT* Whole numberRange -128 to 127Storage: 1 byte

basket_count BYTEINT   +125

SMALLINT Whole number Range: -32,768 to 32,767Storage: 2 bytes

area_code SMALLINT    +00213 (up to 5 digits)

INTEGER Whole number Range: -2,147,483,648 to  2,147,483,647Storage: 4 bytes

phone INTEGER      +0006495252 (up to 10 digits)

BIGINT Whole numberRange ± 9,233,372,036,854,775,807Storage: 8 bytes

international_phone BIGINT+0000010807934842145 (up to 19 digits)

DEC(m, n)DECIMAL(m,n)NUMERIC(m,n)(Small Decimal)

'm' is total number of digits. (m <= 18) 'n' is precision places to the right of decimal point.Max Size =18 digitsStorage: 2 to 8 bytes

salary_amount DEC (10,2)    +00035000.00

DEC(m, n) 'm' is total number of digits. sheet_thickness DEC (32,30)

Page 3: Data Types

DECIMAL(m,n)NUMERIC(m,n)(Large Decimal)

(18 < m <= 38) 'n' is precision places to the right of decimal point.Max Size = 38 digitsStorage: 16 bytes

   +01.123498782792787582977278497827

FLOAT Floating Point Format (IEEE)2x10-307 to 2x10+308

Storage: 8 bytes

salary_factor FLOAT      +4.35400000000000E-001

FLOAT [(precision)]

Internally represented as FLOAT

REAL Internally represented as FLOAT

DOUBLE PRECISION

Internally represented as FLOAT

DATE DATATYPE

EXAMPLE:

Create table employee

( emp_id int,

emp_no int,

first_name char(20),

last_name varchar(20)

emp_add varchar (50),

birth_date date );

here we give the data datatype for the column birth_date.It takes the default date format and the default format is yy/mm/dd.

We also specify the format for date datatype. For example

Create table employee

Page 4: Data Types

( emp_id int,

emp_no int,

first_name char(20),

last_name varchar(20)

emp_add varchar (50),

birth_date date format (dd-mm-yyyy)

);