i've read that the bool type in mysql is an alias of tinyint(1), therefore i should use tinyint
My question is the following: Do i need to declare it unsigned, i mean, is it necessary ?
purchased tinyint(1) unsigned not null DEFAULT 0,
or
purchased tinyint(1) not null DEFAULT 0,
SIGNED, UNSIGNED and ZEROFILL For example, a TINYINT UNSIGNED can range from 0 to 255. Floating point and fixed-point types also can be UNSIGNED , but this only prevents negative values from being stored and doesn't alter the range.
The TINYINT takes 1 byte that means it has range -128 to +127 while int takes 4 bytes; it has range -2147483648 to +2147483647.
There is no difference between TINYINT(1) and Boolean. The keyword Bool or Boolean internally converts into TINYINT(1) or we can say Bool or Boolean are synonymous with TINYINT(1).
While determining whether something is TRUE or FALSE, any int (int, tinyint, smallint, bigint) value converts to a boolean value. If it's 0, it's considered FALSE; if not, it's considered TRUE. So, 2 is also TRUE here. BOOL, BOOLEAN are synonyms for TINYINT(1).
It's not necessary; leave it signed. In fact, it doesn't matter anyway — 0 and 1 are within the range of valid values for TINYINT
regardless of its signedness.
But, seriously, just declare it a BOOL
, it makes it very clear that it's a true-or-false value.
It is not necssary to declare it unsigned, particularly if you're using it to store a boolean value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With