tags:

views:

53

answers:

6

Hello,

I use tinyint (1) for fields which contain either 1 or 0, for xample, is_active. I can use enum ('1','0') instead but not sure which cases I should use enum or tinyint. Any comments/suggetion?

Thanks

Js

A: 

It depends on what the database engine chooses to do under the hood. If you're never going to grow beyond two options, I'd recommend tinyint - but I doubt it makes much of a difference.

Borealid
A: 

My personal preference would be to use TINYINT(1).

LukeH
A: 

BOOL , BOOLEAN. These types are synonyms for TINYINT(1)

I think you should go for tinyint(1)

Bozho
A: 

An enum('active', 'inactive') would use the advantages of an enum better than enum(0, 1).

Sjoerd
A: 

Enum is good if you want to have specific values - for instance:

enum('y','n')

But if you just need a simple boolean, use tinyint(1).

xil3
A: 

In your case both enum and tinyint will have the same size (i.e. 1 byte). However, the enum option is less flexible if your data changes. So use it if you're absolutely sure your data definition will not change (eg. what if you will you be adding a 'disabled' state in the future?).

If you decide to stick with the enum a definition like enum('active', 'not_active') is more practical.

the_void