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:
Typ | Bytes | Signed | Unsigned |
TINYINT | 1 | -128 to | 0 to |
127 | 255 | ||
SMALLINT | 2 | -32.768 to | 0 to |
32.767 | 65.535 | ||
MEDIUMINT | 3 | -8.388.608 to | 0 to |
8.388.607 | 16.777.215 | ||
INT | 4 | -2.147.483.648 to | 0 to |
2.147.483.647 | 4.294.967.295 | ||
BIGINT | 5 | -9.223.372.036.854. | 0 to |
775.808 to 9.223.372. 036.854.775.807 | 18.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
You 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
Windows Batch Script: Computer Shutdown
Tutorial | 2 Comments
MySQL: Add new Column to a Table
Tutorial | 0 Comments
C#/.NET: Difference between int and Int32
Question | 1 Answer
How to Replace multiple Texts at the same Time
Tutorial | 0 Comments
Repair Text Files with mixed Line Breaks
Tutorial | 0 Comments
MySQL: CSV Export as File stored on the Server
Tutorial | 0 Comments
Lazarus: Change Decimal Separator (Dot and Comma)
Question | 1 Answer
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.
Participate
Ask your own question or write your own article on askingbox.com. That’s how it’s done.