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
The maximum unsigned value is
65535
The maximum signed value is
32767
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)
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)
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
Now you can display all records in the table using select statement. The query is as shown below -
mysql> select *from smallIntDemo;
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)
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!