I always thought that the number in the parenthesis represented the field length?
However, I understand that is not always the case. Maybe it’s a MySQL issue? Someone told me if I set a field to 9 characters long, I can add a value that’s more than 9 characters but only the first 9 will be saved.
Example:
CREATE TABLE `person` (
id INT,
age INT(2)
);
If that’s the case, shouldn’t I select something like TINYINT instead of INT for age?
INT(2)will generate an INT with the minimum display width of 2:this does not affect the range of possible values that can be stored in the field; neither is it the number of bytes used to store it. It seems to be only a recommendation for applications how to show the value, unless
ZEROFILLis used (see the linked page).A unsigned
TINYINT(0…255) would probably do as well, unless cryopreservation takes a big step forward during the lifetime of your application.