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.
To set a flag, you can set the type as tinyint(1) type.
Set a database flag. Open the instance and click Edit. Scroll down to the Flags section. To set a flag that has not been set on the instance before, click Add item, choose the flag from the drop-down menu, and set its value.
A flag is a component of a programming language's data structure. A computer interprets a flag value in relative terms or based on the data structure presented during processing, and uses the flag to mark a specific data structure. Thus, the flag value directly impacts the processing outcome.
The active flag piece of data is directly dependent upon the primary key and should be in the table. That table holds data on people, irrespective of the current status of their data.
TINYINT
is perfect for what you are suggesting:
`status` tinyint(1) unsigned NOT NULL DEFAULT '0'
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
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.
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