What does width refer to when referencing numeric variable typesfor MySQL?

Newbie question here:

w3Schools indicates the following:

TINYINT(size) A very small integer. Signed range is from -128 to 127. Unsigned range is from 0 to 255. The size parameter specifies the maximum display width (which is 255)

Does this mean that if I delcare the following: TINYINT(4) unsigned,

  • It can only store data if it is a number between 0 to 4; or
  • It can only store data that consists of 4 digits (0 to 9999)

I suspect it is the latter, so if that is the case, would making is signed (which I believe is the default) would then allow for a range from -9999 to 9999?

1 Like

I think ChatGPT has now given me the required answer:

Therefore, a TINYINT(4) in SQL can still store values between -128 and 127 for a signed TINYINT, or 0 and 255 for an unsigned TINYINT, just like a regular TINYINT data type. The “(4)” only specifies how many digits should be displayed when the data is retrieved, and has no impact on the maximum value that can be stored.

I believe that is correct as I use it for 2FA as True (1) or False (0) thus a TINY INT
requires_2fa tinyint(1) default 1 not null

this is correct but insufficient information

the number of digits (4 in this case) is relevant ~only~ when ZEROFILL is declared for the column

also. please note ZEROFILL is deprecated –

1 Like

Do you know if that also means that width is deprecated, as it has no purpose at all without zerofill?

i would imagine so, but the true extent of my knowledge is limited to what i read in da manual

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.