True/False vs 0/1 in MySQL

后端 未结 4 1324
忘了有多久
忘了有多久 2020-12-02 19:59

Which is faster in a MySQL database? Booleans, or using zero and one to represent boolean values? My frontend just has a yes/no radio button.

4条回答
  •  情深已故
    2020-12-02 20:32

    Bit is also an option if tinyint isn't to your liking. A few links:

    • Which MySQL data type to use for storing boolean values
    • What is the difference between BIT and TINYINT in MySQL?

    Not surprisingly, more info about numeric types is available in the manual.

    One more link: http://blog.mclaughlinsoftware.com/2010/02/26/mysql-boolean-data-type/

    And a quote from the comment section of the article above:

    • TINYINT(1) isn’t a synonym for bit(1).
    • TINYINT(1) can store -9 to 9.
    • TINYINT(1) UNSIGNED: 0-9
    • BIT(1): 0, 1. (Bit, literally).

    Edit: This edit (and answer) is only remotely related to the original question...

    Additional quotes by Justin Rovang and the author maclochlainn (comment section of the linked article).

    Excuse me, seems I’ve fallen victim to substr-ism: TINYINT(1): -128-+127 TINYINT(1) UNSIGNED: 0-255 (Justin Rovang 25 Aug 11 at 4:32 pm)

    True enough, but the post was about what PHPMyAdmin listed as a Boolean, and there it only uses 0 or 1 from the entire wide range of 256 possibilities. (maclochlainn 25 Aug 11 at 11:35 pm)

提交回复
热议问题