Is there a difference in using INT(1) vs TINYINT(1) in MySQL?

前端 未结 3 1070
借酒劲吻你
借酒劲吻你 2020-12-13 03:42

I\'m under the assumption that INT(1) is the exact same thing as TINYINT(1) but I really have no idea. Whenever I\'ve had values that can only be a single integer (e.g. a va

3条回答
  •  既然无缘
    2020-12-13 04:36

    To summarize the accepted answered :

    The number in parentheses indicates the *number of characters to display that field*, **not** the storage size of the field.

    But if you want to know the storage size, you should check the MySQL source documents.

    Source: MySQL Docs: Integer Types (Exact Value) - INTEGER, INT, SMALLINT, TINYINT, MEDIUMINT, BIGINT

    Direct quote from source documentation :

    TINYINT : 1 byte, -128 to 127 signed, 0 to 255 unsigned

    SMALLINT : 2 bytes, -32768 to 32767 signed, 0 to 65535 unsigned

    MEDIUMINT : 3 bytes, -8388608 to 8388607 signed, 0 to 16777215 unsigned

    INT : 4 bytes, -2147483648 to 2147483647 signed, 0 to 4294967295 unsigned

    BIGINT : 8 bytes, -2^63 to 2^63-1 signed, 0 to 2^64-1 unsigned

提交回复
热议问题