开发者

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

开发者 https://www.devze.com 2023-01-27 02: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?

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)?


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.


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号