Reputation: 18594
Which datatype should I use for a flag (in MySQL)? I just want to check if a user is online at the moment.
I thought about a TINYINT or SET which both could be 0 or 1.
Upvotes: 6
Views: 12734
Reputation: 285
TINYINT is the same as a boolean type in MySQL, where 0 is false and 1 is true. You can enter in true or false and it will get evaluated to 1 or 0.
Upvotes: 2
Reputation: 193
Dear Tinyint is better for flag because it's very small int and it also save your bytes more than other. You can also choose char(1) but i will recommend you choose tinyint
Upvotes: 3
Reputation: 19989
TINYINT
is perfect for what you are suggesting:
`status` tinyint(1) unsigned NOT NULL DEFAULT '0'
Upvotes: 9