Reputation: 2315
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
Upvotes: 2
Views: 808
Reputation: 5538
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.
Upvotes: 2
Reputation: 16439
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).
Upvotes: 0
Reputation: 75598
An enum('active', 'inactive')
would use the advantages of an enum better than enum(0, 1)
.
Upvotes: 0
Reputation: 597076
BOOL , BOOLEAN. These types are synonyms for TINYINT(1)
I think you should go for tinyint(1)
Upvotes: 1
Reputation: 98469
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.
Upvotes: 0