0

Let's say I have the following pseudo-table I want to create in MySQL:

CREATE TABLE 'Stuff' (
  'ID' bigint NOT NULL AUTO_INCREMENT,
  'IsAThing' boolean NOT NULL,
  PRIMARY KEY ('ID')
)

As of now (v8.0.x), MySQL doesn't actually have a boolean data type for this and instead, I need to use a TinyInt. In the past, best practice was to use TinyInt(1), where the (1) part isn't so much a data type but a default display configuration (i.e. only display 1 digit of the TinyInt number, even if it was storing the value 100).

However, these days, doing this gives you a warning that Integer display width is deprecated. This question is related but more specifically addresses the use of INT(4). The recommendation there is to either use INT or to ignore the warnings. In that case, I think I would opt to just use INT but my question is more specific to the boolean-equivalent usage.

What is the best practice for this boolean-like data type? Should I just use TINYINT instead of TINYINT(1), given that the feature is now deprecated? Or should I be doing something different? My goal is to not use deprecated features for this new database that will likely live for years through future DB upgrades.

Jaxidian
  • 13,081
  • 8
  • 83
  • 125
  • I think you will find that there has never been a boolean really it has always been a tinyint – RiggsFolly May 14 '20 at 18:02
  • 1
    in our shop, we consistently represent boolean as `TINYINT(1) UNSIGNED COMMENT 'boolean, ...'` and if we don't allow NULL values, then we add `NOT NULL DEFAULT '0'` ... lots of other ways to do it, we just do it like that for consistency. if we start getting problems using the `(1)` length specifier, then we will just drop that, and continue ... – spencer7593 May 14 '20 at 18:07

1 Answers1

1

Display with doesn't really matter. Just use TINYINT. MySQL does have BOOLEAN and you can totally use that as well. It's simply the same thing as TINYINT.

Evert
  • 93,428
  • 18
  • 118
  • 189
  • A lot of connectors automatically convert TINYINT(1) to BOOLEAN and TINYINT to an INT or SIGNED BYTE. This deprecation is going to break a lot of things – Garr Godfrey Mar 07 '22 at 00:54