Careful with Numeric Data Types in MySQL
Posted on July 24th, 2008 by Greg Allard in MySQL | Comments
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.
I use webfaction to host a lot of my django projects. It has an easy setup that will get you developing quickly and a great community of talented programmers. There is also a quick setup for rails, wordpress, and a lot more.
Related posts:
- Tips for MySQL to PostgreSQL Switch If you’ve decided to move a few tables from MySQL to PostgreSQL, these few tips might help. I won’t get...
- How To Use Triggers to Track Changes in MySQL Setting constraints and rules in the database is better than writing special code to handle the same task since it...
- How to Break a MySQL Left Join Care must be taken when placing conditions on the results of the right-hand table of a LEFT JOIN because it...