Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

The int size is neither bits nor bytes. It's just the display width, that is used when the field has ZEROFILL specified.

This blog explains the meaning of int(size) in MySQL.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top