00 Votes

MySQL: Integer Types

Info by Stefan Trost | Last update on 2023-01-31 | Created on 2012-03-11

MySQL provides some different integer types such as TINYINT, SMALLINT, MEDIUMINT, INT and BIGINT. All of these types are saving integer values, that means values without a comma. The difference between the types lies in the number of bytes used for the storage of the numbers.

Accordingly, depending on how many bytes are reserved for the respective integer type, different ranges of values can be saved with the various types:

TINYINT1-128 to0 to
SMALLINT2-32.768 to0 to
MEDIUMINT  3-8.388.608 to0 to
INT4-2.147.483.648 to0 to
BIGINT5-9.223.372.036.854. 0 to
  775.808 to 9.223.372. 036.854.775.80718.446.744.073.709. 551.615

The smallest data type TINYINT only uses one byte of memory. So, with this byte, TINYINT can store values from -128 to 127. If we are using the attribute UNSIGNED, so that only positive values can be saved, the range of possible values changes to 0 to 255.

What data type should I use?

Think carefully about which range of numbers you want to store in your database exactly. If your integer values never rise above 65,000 and the values can not be negative, you should specify the appropriate column as the type SMALLINT. With this, a value consumes only 2 bytes. This is half of what it would consume when saved as a standard integer (INT).


About the Author

AvatarYou can find Software by Stefan Trost on sttmedia.com. Do you need an individual software solution according to your needs? - sttmedia.com/contact
Show Profile


Related Topics

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.


Ask your own question or write your own article on askingbox.com. That’s how it’s done.