Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which datatype for flag?

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.

like image 275
Evgenij Reznik Avatar asked Apr 28 '12 22:04

Evgenij Reznik


People also ask

What is the data type for flag in SQL?

To set a flag, you can set the type as tinyint(1) type.

How do you flag in SQL?

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.

What are flag values?

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.

What is Active flag in SQL?

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.


3 Answers

TINYINT is perfect for what you are suggesting:

`status` tinyint(1) unsigned NOT NULL DEFAULT '0'
like image 163
Mike Purcell Avatar answered Sep 17 '22 22:09

Mike Purcell


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

like image 33
StormMan Avatar answered Sep 20 '22 22:09

StormMan


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.

like image 34
island_hopper Avatar answered Sep 21 '22 22:09

island_hopper