Does MySQL boolean 'tinyint(1)' support up to 127?

PHPz
Release: 2023-09-19 16:29:04
forward
987 people have browsed it

MySQL 布尔值“tinyint(1)”是否最多支持 127?

Let us understand some key points about TINYINT type in MySQL -

  • TINYINT type occupies 1 byte i.e. 8 bits.
  • TINYINT(N), where N represents the display width you want.

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.
Copy after login

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)
Copy after login

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
Copy after login

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)
Copy after login

Use select statement to display all records in the table. The query is as follows -

mysql> select *from Display;
Copy after login

Output

+-----------+ | rangeOfId | +-----------+ | 127 | | -128 | +-----------+ 2 rows in set (0.00 sec)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!