在规划DB2数据库的时候,在参加一些考试的时候,可能会需要计算一下数据可能存储的空间。下面是我笔记中的相关内容。
*********************************
Numeric Data Types
*********************************
Small integer:
−32,768 to 32,767
2 bytes of storage space
SMALLINT
Integer:
−2,147,483,648 to 2,147,483,647
4 bytes of storage space
INTEGER and INT
Big integer:
−9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
8 bytes of storage space
BIGINT
Decimal:
The maximum precision allowed for decimal values is 31 digits
Precision ÷ 2 (truncated) + 1 = Bytes required. (For example, the value 67.12345 has precision of 7, 7 ÷ 2 is 3, + 1 makes 4; therefore, 4 bytes are required to store the value 67.12345.)
DECIMAL, DEC, NUMERIC, and NUM
Single-precision floating-point:
−3.402E+38 to −1.175E-37 or 1.175E-37 to 3.402E+38. (is used to store a 32-bit approximation of a real number.)
Each single-precision floating-point value can be up to 24 digits in length
4 bytes of storage space
REAL and FLOAT
Double-precision floating-point
−1.79769E+308 to −2.225E-307 or 2.225E-307 to 1.79769E+308. (used to store a 64-bit approximation of a real number. )
Each double-precision floating-point value can be up to 53 digits in length
8 bytes of storage space
DOUBLE, DOUBLE PRECISION, and FLOAT
*********************************
Character String Data Types
*********************************
Fixed-length caracter string:
between 1 and 254 characters in length
(Number of characters × 1) = Bytes required
CHARACTER and CHAR
Varying-length character sting:
up to 32,672 characters in length
tablespaces that use 4K pages, varying-length character string values cannot be more than 4,092 characters in length; for tables that reside in a tablespaces that use 8K pages, varying-length character string values cannot be more than 8,188 characters in length, and so on.
(Number of characters × 1) + 4 = Bytes required.
CHARACTER VARYING, CHAR VARYING, and VAR-CHAR
Fixed-length double-byte character string:
up to 127 characters in length
(Number of characters × 2) = Bytes required
GRAPHIC
Varying-length double-byte character string:
up to 16,336 characters in length
For tables that reside in tablespaces that use 4K pages, varying-length double-byte character string values cannot be more than 2,046 characters in length; for tables that reside in a tablespaces that use 8K pages, varying-length double-byte character string values cannot be more than 4,094 characters in length; and so on.
(Number of characters × 2) + 24 = Bytes required
LONG VARGRAPHIC
*********************************
Date/Time Data Types
*********************************
Date:
The range for the year portion is 0001 to 9999; the range for the month portion is 1 to 12; and the range for the day portion is 1 to 28, 29, 30 or 31
10 characters in length
4 bytes of storage space
DATE
Time:
The range for the hours portion is 0 to 24; the range for the minutes portion is 0 to 59; and the range for the seconds portion is 0 to 59.
8 characters in length
3 bytes of storage space
TIME
Timestamp:
The range for the year portion is 0001 to 9999; the range for the month portion is 1 to 12; and the range for the day portion is 1 to 28, 29, 30 or 31
the range for the hours portion is 0 to 24; the range for the minutes portion is 0 to 59; the range for the seconds portion is 0 to 59; and the range for the microseconds portion is 0 to 999,999.
26 characters in length
10 bytes of storage space