Home >Database >Mysql Tutorial >Does MySQL boolean 'tinyint(1)' support up to 127?
Let us understand some key points about TINYINT type in MySQL -
For example, TINYINT(1) can be used to display a width of 1.
Let us understand the minimum and maximum values -
The maximum value for tinyint is= (2(8-1)-1) = 127 The minimum value for tinyint is = -(2(8-1)) = -128.
The value will be between -128 to 127. This means that TINYINT (1) does not affect the maximum and minimum values of tinyint.
Let's check it out -
First, create a table with its columns set to TINYINT (1) -
mysql> create table Display -> ( -> rangeOfId tinyint(1) -> ); Query OK, 0 rows affected (0.67 sec)
Let's insert a value that is outside the maximum and minimum range . This will result in the error -
mysql> insert into Display values(128); ERROR 1264 (22003): Out of range value for column 'rangeOfId' at row 1
The query to insert records is as follows. We will now insert values in the range -
mysql> insert into Display values(127); Query OK, 1 row affected (0.18 sec) mysql> insert into Display values(-128); Query OK, 1 row affected (0.20 sec)
Use select statement to display all records in the table. The query is as follows -
mysql> select *from Display;
+-----------+ | rangeOfId | +-----------+ | 127 | | -128 | +-----------+ 2 rows in set (0.00 sec)
The above is the detailed content of Does MySQL boolean 'tinyint(1)' support up to 127?. For more information, please follow other related articles on the PHP Chinese website!