mysql-data-types
mysql-data-types
Properly defining the fields in a table is important to the overall optimization of your database. You
should use only the type and size of field you really need to use; don't define a field as 10
characters wide if you know you're only going to use 2 characters. These types of fields orcolumns
are also referred to as data types, after the type of data you will be storing in those fields.
MySQL uses many different data types broken into three categories: numeric, date and time, and
string types.
INT - A normal-sized integer that can be signed or unsigned. If signed, the allowable range is
from -2147483648 to 2147483647. If unsigned, the allowable range is from 0 to
4294967295. You can specify a width of up to 11 digits.
TINYINT - A very small integer that can be signed or unsigned. If signed, the allowable range
is from -128 to 127. If unsigned, the allowable range is from 0 to 255. You can specify a width
of up to 4 digits.
SMALLINT - A small integer that can be signed or unsigned. If signed, the allowable range is
from -32768 to 32767. If unsigned, the allowable range is from 0 to 65535. You can specify a
width of up to 5 digits.
BIGINT - A large integer that can be signed or unsigned. If signed, the allowable range is
from -9223372036854775808 to 9223372036854775807. If unsigned, the allowable range is
from 0 to 18446744073709551615. You can specify a width of up to 20 digits.
FLOATM, D - A floating-point number that cannot be unsigned. You can define the display
length M and the number of decimals D. This is not required and will default to 10,2, where 2
is the number of decimals and 10 is the total number of digits includingdecimals. Decimal
precision can go to 24 places for a FLOAT.
DOUBLEM, D - A double precision floating-point number that cannot be unsigned. You can
define the display length M and the number of decimals D. This is not required and will
default to 16,4, where 4 is the number of decimals. Decimal precision can go to 53 places for
a DOUBLE. REAL is a synonym for DOUBLE.
DATE - A date in YYYY-MM-DD format, between 1000-01-01 and 9999-12-31. For example,
December 30th, 1973 would be stored as 1973-12-30.
DATETIME - A date and time combination in YYYY-MM-DD HH:MM:SS format, between 1000-
01-01 00:00:00 and 9999-12-31 23:59:59. For example, 3:30 in the afternoon on December
30th, 1973 would be stored as 1973-12-30 15:30:00.
TIMESTAMP - A timestamp between midnight, January 1, 1970 and sometime in 2037. This
looks like the previous DATETIME format, only without the hyphens between numbers; 3:30
in the afternoon on December 30th, 1973 would be stored as 19731230153000
YYYYMMDDHHMMSS.
String Types:
Although numeric and date types are fun, most data you'll store will be in string format. This list
describes the common string datatypes in MySQL.
VARCHARM - A variable-length string between 1 and 255 characters in length; for example
VARCHAR25. You must define a length when creating a VARCHAR field.
BLOB or TEXT - A field with a maximum length of 65535 characters. BLOBs are "Binary
Large Objects" and are used to store large amounts of binary data, such as images or other
types of files. Fields defined as TEXT also hold large amounts of data; the difference between
the two is that sorts and comparisons on stored data are case sensitive on BLOBs and are not
case sensitive in TEXT fields. You do not specify a length with BLOB or TEXT.
ENUM - An enumeration, which is a fancy term for list. When defining an ENUM, you are
creating a list of items from which the value must be selected oritcanbeNULL. For example, if
you wanted your field to contain "A" or "B" or "C", you would define your ENUM as ENUM
′ A ′ , ′ B ′ , ′ C ′ and only those values orNULL could ever populate that field.
Loading [MathJax]/jax/output/HTML-CSS/jax.js