I can understand that if you UPDATE a TINYINT(1)
column and pass a value of 1 or 0 it will convert it to TRUE or FALSE, respectively.
I'm just confused on what happens when you UPDATE the column with a different value, say 2. In other words, if you UPDATE a TINYINT(1)
column with the value 2, will this be TRUE or FALSE? Or, is this even doable?
Best Answer
A tinyint column can hold values from 0 to 255 (if it is defined as
unsigned
) or -128 to +127 (if it issigned
). The(1)
intinyint(1)
is only for some formatting options and generally ignored. You could create it astinyint(100)
and it wouldn't make a difference.Regarding the
TRUE
orFALSE
, any int (int, tinyint, smallint, bigint) value can be used as (or converted to) a boolean value. It is consideredFALSE
if it is0
andTRUE
otherwise. So,2
would count asTRUE
.To be entirely clear, MySQL does not have a true
BOOLEAN
type.BOOLEAN
is a synonym ofTINYINT(1)
, as the docs explain in Numeric Type Overview: