Use: INT(11)
.
MySQL indexes will be able to parse through an int list fastest.
Use: BINARY(x)
, or BLOB(x)
.
You can store security tokens, etc., as hex directly in BINARY(x) or BLOB(x). To retrieve from binary
-type, use SELECT HEX(field)...
or SELECT ... WHERE field = UNHEX("ABCD....")
.
Use: DATETIME
, DATE
, or TIME
.
Always use DATETIME
if you need to store both date and time (instead of a pair of fields), as a DATETIME
indexing is more amenable to date-comparisons in MySQL.
Use: BIT(1)
(MySQL 8-only.) Otherwise, use BOOLEAN(1)
.
BOOLEAN
is actually just an alias of TINYINT(1)
, which actually stores 0 to 255 (not exactly a true/false, is it?).
Use: INT(11)
.
VARCHAR or other types of fields won't work with the SUM()
, etc., functions.
Use: TEXT.
Max limit is 65,535.
Use: MEDIUMTEXT.
Max limit is 16,777,215.
Use: LONGTEXT.
Max limit is 4,294,967,295.
Use : VARCHAR(255)
.
UTF-8 characters can take up three characters per visible character, and some cultures do not distinguish firstname and lastname. Additionally, cultures may have disagreements about which name is first and which name is last. You should name these fields Person.GivenName
and Person.FamilyName
.
Use : VARCHAR(256)
.
The definition of an e-mail path is set in RFC821 in 1982. The maximum limit of an e-mail was set by RFC2821 in 2001, and these limits were kept unchanged by RFC5321 in 2008. (See the section: 4.5.3.1. Size Limits and Minimums.) RFC3696, published 2004, mistakenly cites the email address limit as 320
characters, but this was an "info-only" RFC that explicitly "defines no standards" according to its intro, so disregard it.
Use: VARCHAR(255)
.
You never know when the phone number will be in the form of "1800...", or "1-800", or "1-(800)", or if it will end with "ext. 42", or "ask for susan".
Use: VARCHAR(10)
.
You'll get data like 12345
or 12345-6789
. Use validation to cleanse this input.
Use: VARCHAR(2000)
.
Official standards support URL's much longer than this, but few modern browsers support URL's over 2,000 characters. See this SO answer: What is the maximum length of a URL in different browsers?
Use: DECIMAL(11,2)
.
It goes up to 11.