tinyint(1) for mysql

Recently, my younger brother discovered a special situation when using mysql to access data. That is, a field type in a library table is tinyint(1). If there are only two values, 0 and 1, respectively, the corresponding false and true are taken out in the java program.

In this case, I specifically asked Du Niang and found that this is a feature of the mysql database. If the field of type tinyint is only 1 in length, it will be taken out. It will be converted to false and true by default, and the same when it exists. If you store a number other than 0 and 1, it will only be 1.

So, to store a boolean value in mysq, use the tinyint(1) field. 0 is false and 1 is true.

If you store numbers such as 0, 1, 2, 3, 4, 5, 6, 7, and 8, use the tinyint(4) field.

If you have to take out the numbers 0 and 1 of the tinyint(1) field, you need to add *1 when taking out the corresponding field

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325566201&siteId=291194637