Careful with Numeric Data Types in MySQL
Posted on July 24th, 2008 by Greg Allard in MySQL |
TINYINT can be set to length of 4, but that doesn’t mean the max value is 9999. A tiny int will always have the same range no matter what size you specify since that isn’t what it is for with integers. It is the display width for the command line output.
This is what I was able to find in the MySQL manual:
The display width does not constrain the range of values that can be stored in the column, nor the number of digits that are displayed for values having a width exceeding that specified for the column.
Reading the manual for things like this isn’t something people normally do. I had no idea about this until recently and I’ve been using MySQL for a long time.
Reference Chart for Max Signed Integers
| TINYINT | 127 |
|---|---|
| SMALLINT | 32767 |
| MEDIUMINT | 8388607 |
| INT | 2147483647 |
| BIGINT | 9223372036854775807 |
However, CHAR and VARCHAR work as expected with these limits.
Add New Comment
Viewing 1 Comment
Thanks. Your comment is awaiting approval by a moderator.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Add New Comment
Trackbacks