0

I'm a bit confused with the MySQL Documentation with regards to the storage requirements for various fields. I'm currently working with redesigning a database and I'm seeing TINYINT(4) as they data type. Previously I've never given any thought to this, but will this require one byte and just truncate the last digit off the number, or will it actually require 2 bytes and be converted to a SMALLINT internally?

EDIT - I know that the number represents the amount of digits that will be displayed, like TINYINT(2) will only show 2 digits or whatever, but what if that number is more than the data type can actually hold?

iLikeBreakfast
  • 1,545
  • 23
  • 46

1 Answers1

0

As you stated correctly the TINYINT type uses 1 byte of storage for 256 possible integer values (-128 through 127) or UNSIGNED 0-255. See that -128? This is (along with ZEROFILL) the reason for (4). But it won´t get converted to a SMALLINT automatically, so choose your data type accordingly. See this link, this blog deals with the topic (as mentioned in answer here).

Community
  • 1
  • 1
Sebastian
  • 451
  • 6
  • 19