search

Home  >  Q&A  >  body text

mysql - 为什么不推荐用tinyint?

我们做的一个项目,把建表的sql语句发给DBA审核,DBA提出了几个意见,其中一条是不建议使用tinyint字段,那个字段type的值可能是1或者2,所以我们用tinyint,以前都是这样用啊。

为什么DBA不推荐使用tinyint呢?

迷茫迷茫2782 days ago956

reply all(5)I'll reply

  • 大家讲道理

    大家讲道理2017-04-17 13:11:47

    Everyone has their own ideas. I prefer to use tinyint, which only occupies one byte. Using enum is inflexible. For example, if 1 is defined as male and 2 is female, if I want to display 1 as male, 2 is a woman, so it is inconvenient.

    On MYSQL, it is not recommended to use NULL. NULL takes up four characters and records too much. This is unnecessary loss. When querying, use where field is null or field is not null, like this The query is not very efficient. Set the field to default '', so that it can be where field = '' or field != '', or it is not allowed to be empty NOT NULL.

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-17 13:11:47

    I am a half-experienced DBA. I may not know which book I read this in. Our company’s DBA does not allow fields to be NULL, and there are even more bizarre ones.

    This is just like when goto was not allowed to be used in C language programming, a half-baked “expert”

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-17 13:11:47

    type Using 1,2 is not a good design in itself. Over time, you always need to look at the code to understand the meaning. It's much better to use enum types and give each type an appropriate name.

    But if this field requires related queries, it is not recommended to use it, as the performance will be severely degraded.

    reply
    0
  • ringa_lee

    ringa_lee2017-04-17 13:11:47

    When connecting Java to MySQL, I don’t recognize tinyint, only 0 and 1

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-17 13:11:47

    It makes sense to use tinyint. Don't listen to the DBA nonsense.

    reply
    0
  • Cancelreply