-2

When not relying on the default max length of integer fields, when you want to specifically limit the field to a certain length, what is best practice?

Is there any difference between using TINYINT(1), SMALLINT(1), INT(1), etc.? Are the other integer types just aliases or are they real types?

If there is no benefit to using the other integer types (when the length is not left open), should I just stick to INT(n) for tidiness? i.e. Does using any of the other integer types actually add anything beneficial unless leaving them open to their default max length?

BadHorsie
  • 14,135
  • 30
  • 117
  • 191
  • I think the only differences if performance wise, different datatype uses different amount of bytes in computer memory –  Oct 14 '13 at 10:44
  • If everything else fails, read the manual: http://dev.mysql.com/doc/refman/5.5/en/numeric-type-attributes.html –  Oct 14 '13 at 11:52

1 Answers1

2

I think the difference is the consumption of memory of each type. Where a TINYINT uses 1 byte, SMALLINT takes 2 bytes, INT takes 4 bytes and BIGINT 8 bytes (see manual). This can influence the performance.

The (optional) value in the parentheses addresses how the values are displayed/printed. It is commonly used when you want to fill up small numbers with zeros on the left (there is also the ZEROFILL option).

Jost
  • 1,549
  • 12
  • 18