What is the difference between BIT and TINYINT in MySQL?

前端 未结 6 961
耶瑟儿~
耶瑟儿~ 2020-11-29 00:10

In which cases would you use which? Is there much of a difference? Which I typically used by persistence engines to store booleans?

6条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-29 00:28

    From Overview of Numeric Types;

    BIT[(M)]

    A bit-field type. M indicates the number of bits per value, from 1 to 64. The default is 1 if M is omitted.

    This data type was added in MySQL 5.0.3 for MyISAM, and extended in 5.0.5 to MEMORY, InnoDB, BDB, and NDBCLUSTER. Before 5.0.3, BIT is a synonym for TINYINT(1).

    TINYINT[(M)] [UNSIGNED] [ZEROFILL]

    A very small integer. The signed range is -128 to 127. The unsigned range is 0 to 255.

    Additionally consider this;

    BOOL, BOOLEAN

    These types are synonyms for TINYINT(1). A value of zero is considered false. Non-zero values are considered true.

提交回复
热议问题