MEDIUMINT[(
width)] UNSIGNED [ZEROFILL]
Stores integer (whole number) values in the range –8,388,608 to 8,388,607. The
width,
UNSIGNED, and
ZEROFILL
options behave as for INT. When
UNSIGNED
is used,
a column can store values in the range 0 to 16,777,215. A
MEDIUMINT
column requires three bytes of storage space.
BIGINT[(
width)] UNSIGNED [ZEROFILL]
Stores integer (whole number) values in the range –9,223,372,036,854,775,808 to. The
width, UNSIGNED, and
ZEROFILL
options behave as for INT. When
UNSIGNED
is used, a column can store values in the range 0 to. A
BIGINT
column requires eight bytes of storage space.
Other rational number typesIn Common column types
we discussed the fixed-point DECIMAL
type. There are two other types that support decimal points
DOUBLE
(also known as REAL) and FLOAT. They’re designed to store approximate numeric values rather than
the exact values stored byDECIMAL
. Why would you want approximate values The answer is that many numbers with a decimal point are approximations of real quantities. For example, suppose you earn $50,000 per annum and you want to store it as a monthly wage. When you convert
it to a per-month amount, it’s $4,166 plus 66 and 2/3rds cents. If you store this as, it’s not exact enough to convert to a yearly wage (since 12 multiplied by is $50,000.04). However, if you store 2/3rds
with enough decimal places,
it’s a closer approximation, and you’ll find that it is accurate enough to correctly multiply to obtain the original value in a high-precision environment such as MySQL.
That’s where
DOUBLE
and
FLOAT
are useful they let you store values such as 2/3rds or pi with a
large number of decimal places, allowing accurate approximate representations of exact quantities.
Let’s continue the previous example using DOUBLE. Suppose you create a table as follows:
mysql>
CREATE TABLE wage (monthly DOUBLE);Query OK, 0 rows affected (0.09 sec)
You can now insert the monthly wage using:
mysql>
INSERT INTO wage VALUES (50000/12);Query OK, 1 row affected (0.00 sec)
When you multiply it to a yearly value, you get an accurate approximation:
mysql>
SELECT monthly FROM wage;+------------+
| monthly |
+------------+
| 50000 |
+------------+
1 row inset sec)
Here are the details of the
DOUBLE
and
FLOAT
types:
Share with your friends: