Just I wonder why the range is given with the my sql data types. I define a table with a field name \"id\" and the data type is \"int(2)\". I inserted the value to the field
As far as I know, when you define INT(2)
(where maximum value is 4), you are allocating in memory 2 bits, but if you insert value, which is bigger, then 4, MySQL will request more memory from system.
So INT(2)
means allocate at least 2 bits for storing this value, if value bigger, then you specified (INT(2)
), DBMS will request memory ones again to request this memory. This is no good for performance reason to request memory twice, that's why better to allocate for column more space.