Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flag columns, Varchar or INT?

Tags:

php

mysql

I often use (what I call) 'flag' columns in my DBs, such as the following:

Column 'Type':
0 = CREATOR
1 = OPERATIVE
2 = APPROVER 

But is this the right way to do this? I only ask because it might be confusing coming back to it later when I don't remember what zero, one, two, or three mean. Wouldn't it be better to simple mark them as CREATOR etc?

What is the general accepted practice for this?

like image 508
Chud37 Avatar asked Mar 20 '26 19:03

Chud37


1 Answers

A flag is typically a boolean true and false or 0 and 1 expressed in a bit (MySQL 5.0.3+), or tinyint. If you have more than 2 possible values, those values could be stored in an ENUM within MySQL, otherwise, those possible values should be stored in their own table and referenced using a foreign key relationship (normalization).

like image 67
Kermit Avatar answered Mar 23 '26 07:03

Kermit