DB2 Basic Data Types (Integer, Floating-point, Character, Date, etc.)
Integer Data Types
Integer data types refer to data types that can store integer values, including INT, SMALLINT and TINYINT. They support different maximum value ranges respectively used for representing small, medium and large integer values.
INT
- Supported Value Range: -2147483648 to 2147483647
- Use Cases: Storing small integer values such as user IDs
SMALLINT
- Supported Value Range: -32768 to 32767
- Use Cases: Storing medium-sized integer values, for example order ID
TINYINT
- Supported Value Range: -128 to 127
- Use Cases: Storing small integer values such as boolean values (0 or 1)
Floating-point Data Types
Floating-point data types refer to data types that can store floating-point numeric values, including FLOAT and DOUBLE. They support different levels of precision respectively used for representing low-precision and high-precision floating-point values.
FLOAT
- Supported Value Range: Unrestricted but lower precision
- Use Cases: Storing floating-point numbers requiring lower precision such as temperature or acceleration
DOUBLE
- Supported Value Range: Unrestricted but higher precision
- Use Cases: Storing floating-point numbers requiring higher precision, for example scientific calculations or image processing
Character Data Types
Character data types refer to data types that can store byte sequences (which may include spaces), including VARCHAR and CHAR. They support different maximum lengths respectively used for representing variable-length and fixed-length string values.
VARCHAR
- Supported Value Range: 1 to 65535 characters
- Use Cases: Storing variable-length strings such as user names or description information
CHAR
- Supported Value Range: 1 to 255 characters
- Use Cases: Storing fixed-length string values, for example product names or codes
Date Data Types
Date data types refer to data types that can store date values, including DATE and TIMESTAMP. They support different levels of precision respectively used for representing simple dates and complex dates containing time information.
DATE
- Supported Value Range: -290177 to 126071 (exclusive)
- Use Cases: Storing simple date values such as birthdays or event dates
TIMESTAMP
- Supported Value Range: -1970-01-01 to 2105-12-31 (exclusive)
- Use Cases: Storing complex dates containing time information, for example record timestamps