07/27: MySQL > Numeric Data Types
Category: Study
Posted by: hajime osako
Integer Data Types
The number 4 is the display width which is unrelated to the range of the data type.
Values shorter than the display width are padded with spaces as necessary.
It won't cause output truncation.
INT(4) column does not require half as much storage per value at INT(8). All INT data type require 4 bytes.
No display width is specified, MySQL use the width of the full range of values for the type. Ex: SMALLINT is 6 because the widest is -32768.
Floating-Point Data Types
FLOAT and DOUBLE may be used to represent approximate-value numbers in the native binary floating-point format used by the server host's CPU.
Fixed-Point Data Types (DECIMAL)
The defaults for omitted precision and scale are 10 and 0.
The amount of storage required for DECIMAL is approximately four bytes are required per nine digits on each side of the decimal point.
The BIT Data Type
BIT(n) column presents the range of value 0 to 2n -1, and the storage requirement is approximately INT((n+7/8) bytes per value.
To wirete literal bit values, the leteral-value notation b'xxx' can be used. For example, b'1111' equals 15.
TINYINT 1 byte SMALLINT 2 bytes MEDIUMINT 3 bytes INT 4 bytes BIGINT 8 bytesINT(4)
The number 4 is the display width which is unrelated to the range of the data type.
Values shorter than the display width are padded with spaces as necessary.
It won't cause output truncation.
INT(4) column does not require half as much storage per value at INT(8). All INT data type require 4 bytes.
No display width is specified, MySQL use the width of the full range of values for the type. Ex: SMALLINT is 6 because the widest is -32768.
Floating-Point Data Types
FLOAT and DOUBLE may be used to represent approximate-value numbers in the native binary floating-point format used by the server host's CPU.
FLOAT 4 bytes DOUBLE 8 bytesYou can specify explicit precision and scale, but if you don't, MySQL uses the maximum accuracy allowed by the hardware. Floating-point values are stored using mantissa/exponent representation.
Fixed-Point Data Types (DECIMAL)
The defaults for omitted precision and scale are 10 and 0.
The amount of storage required for DECIMAL is approximately four bytes are required per nine digits on each side of the decimal point.
The BIT Data Type
BIT(n) column presents the range of value 0 to 2n -1, and the storage requirement is approximately INT((n+7/8) bytes per value.
To wirete literal bit values, the leteral-value notation b'xxx' can be used. For example, b'1111' equals 15.