Which MySQL data type to use for storing boolean values

前端 未结 13 1613
感情败类
感情败类 2020-11-22 04:45

Since MySQL doesn\'t seem to have any \'boolean\' data type, which data type do you \'abuse\' for storing true/false information in MySQL?

Especially in the context

13条回答
  •  悲&欢浪女
    2020-11-22 05:25

    You can use BOOL, BOOLEAN data type for storing boolean values.

    These types are synonyms for TINYINT(1)

    However, the BIT(1) data type makes more sense to store a boolean value (either true[1] or false[0]) but TINYINT(1) is easier to work with when you're outputting the data, querying and so on and to achieve interoperability between MySQL and other databases. You can also check this answer or thread.

    MySQL also converts BOOL, BOOLEAN data types to TINYINT(1).

    Further, read documentation

提交回复
热议问题