Difference between “int” and “int(2)” data types in my sql

前端 未结 4 2201
没有蜡笔的小新
没有蜡笔的小新 2020-12-08 02:16

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

4条回答
  •  太阳男子
    2020-12-08 02:39

    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.

提交回复
热议问题