enum('yes', 'no') vs tinyint -- which one to use?
Asked Answered
P

3

18

What's the best practice for fields that hold true/false values?

Such columns can be defined as enum('yes','no') or as tinyint(1). Is one better/faster than the other?

Is it better to use enum('1','0') vs. enum('yes','no') (i.e., does it write 'yes' or 'no' as a string to every row so the database storage size gets bigger)?

Photogravure answered 28/11, 2010 at 14:14 Comment(1)
A boolean is basically a tinyint(1).Barnebas
G
11

Also, ENUM is a non-standard MySql extension. You should avoid it, especially if you can achieve the same results in a standard way.

Gangboard answered 28/11, 2010 at 14:28 Comment(0)
F
15

avoid enum from this reasons

The bottom line is that ENUM has its place, but should be used sparingly. The model should enforce the constraints, not the database; the model should handle interpreting raw data into useful information for your views, not the database.

Feedback answered 28/11, 2010 at 14:39 Comment(0)
S
12

BOOLEAN type is there for a reason. It is indeed a TINYINT(1) but since it's there, it must be the recommended way.

Stake answered 28/11, 2010 at 14:27 Comment(0)
G
11

Also, ENUM is a non-standard MySql extension. You should avoid it, especially if you can achieve the same results in a standard way.

Gangboard answered 28/11, 2010 at 14:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.