Home > Database > Mysql Tutorial > What is the maximum value of smallint(6) unsigned in MySQL?

What is the maximum value of smallint(6) unsigned in MySQL?

WBOY
Release: 2023-08-23 21:49:06
forward
1877 people have browsed it

在MySQL中,smallint(6) unsigned的最大值是多少?

The maximum value of SMALLINT(6) unsigned in MySQL is 65535. The number 6 does not affect the actual range, it is only used to display the width on the command line.

The minimum signed value is

-32768
Copy after login

The maximum unsigned value is

65535
Copy after login

The maximum signed value is

32767
Copy after login

Let’s do this by using zerofill Understand the problem and create a table using the following query.

mysql> create table smallIntDemo
-> (
-> FirstNumber smallint(6) zerofill
-> );
Query OK, 0 rows affected (1.95 sec)
Copy after login

Now you can use insert command to insert records in the table. Whenever you insert a value outside the range of 65535, it will not be inserted into the table because that is the maximum value. The query is as follows, inserting values ​​smaller than the maximum range.

mysql> insert into smallIntDemo values(2);
Query OK, 1 row affected (0.21 sec)

mysql> insert into smallIntDemo values(23);
Query OK, 1 row affected (0.21 sec)

mysql> insert into smallIntDemo values(234);
Query OK, 1 row affected (0.17 sec)

mysql> insert into smallIntDemo values(2345);
Query OK, 1 row affected (0.15 sec)

mysql> insert into smallIntDemo values(23456);
Query OK, 1 row affected (0.48 sec)
Copy after login

Now, let us look at some records that will not be inserted into the table because it exceeds the maximum value.

mysql> insert into smallIntDemo values(234567);
ERROR 1264 (22003): Out of range value for column 'FirstNumber' at row 1

mysql> insert into smallIntDemo values(111111);
ERROR 1264 (22003): Out of range value for column 'FirstNumber' at row 1
Copy after login

Now you can display all records in the table using select statement. The query is as shown below -

mysql> select *from smallIntDemo;
Copy after login

The following is the output showing the width i.e. number used, i.e. SMALLINT(6). Width is 6.

+-------------+
| FirstNumber |
+-------------+
| 000002 |
| 000023 |
| 000234 |
| 002345 |
| 023456 |
+-------------+
5 rows in set (0.00 sec)
Copy after login

The above is the detailed content of What is the maximum value of smallint(6) unsigned in MySQL?. 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template