MySQL的三态场 [英] MySQL Tri-state field

查看:145
本文介绍了MySQL的三态场的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创造一个良好的/中性/坏领域。哪一个会更理解/正确的方式。

I need to create a good/neutral/bad field. which one would be the more understandable/correct way.


  1. 与空(1 =好,空=中性,0 =坏)
  2. 系统二进制领域
  3. 的int(1 =好,2 =中性的,3 =坏)

  4. 的枚举(良好,中性,坏)

  5. 任何其他

  1. A binary field with null (1=good, null=neutral, 0=bad)
  2. An int (1=good, 2=neutral, 3=bad)
  3. An enum (good, neutral, bad)
  4. Any other

这是唯一和信息领域,我不需要这个搜索。

It's only and informative field and I will not need to search by this.

推荐答案

NULL值应保留或者:

NULL values should be reserved for either:


  • 未知值;或

  • 不适用的价值观;

这两者都不是的情况下在这里。

neither of which is the case here.

我就简单存储 CHAR 看重自己,设定一个 {'G','N','B'} 。这可能是最简单的解决方案,占用空间小,同时还提供助记符值(容易转换'G'到'好'为例)。

I would simply store a CHAR value myself, one of the set {'G','N','B'}. That's probably the easiest solution and takes up little space while still providing mnemonic value (easily converting 'G' to 'Good' for example).

如果你不太在意空间,那么你甚至可以将它们存储为 VARCHAR(7)或同等学历并存储的实际值 { '好','中性','坏'} 所以没有翻译都将需要在你的选择语句(假定这些都是你会被打印实际值)。

If you're less concerned about space, then you could even store them as varchar(7) or equivalent and store the actual values {'Good','Neutral','Bad'} so that no translation at all would be needed in your select statements (assuming those are the actual values you will be printing).

这篇关于MySQL的三态场的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆