Is it useful to limit the number of digits as int(5)
when creating a MySQL table? I think int(5)
and int(11)
are almost the same and use 4 bytes of storage. Similar case of varchar(50)
and varchar(255)
. Am I right? Or it has benefit to limit the number of characters (digits) when creating a table?
int(5)
and int(11)
are stored in the same way, the number is just a representational option called "display width". It may be used by some applications to pad the field when displaying it.
With varchar
, the number indicates an upper limit of the length of the string that may be stored. Since varchar
fields are of a variable size, the actual used bytes may be equal to or less than that. This limit may even be used as a rudimentary form of validation.